Added in ctor/dtor counting

This commit is contained in:
kipp%netscape.com 1999-10-05 14:53:40 +00:00
parent b2b1eab47b
commit de44833a85
14 changed files with 160 additions and 9 deletions

View File

@ -1390,6 +1390,8 @@ static PRBool HashStyleRule(nsISupports* aRule, void* aData)
return PR_TRUE;
}
MOZ_DECL_CTOR_COUNTER(StyleContextImpl);
StyleContextImpl::StyleContextImpl(nsIStyleContext* aParent,
nsIAtom* aPseudoTag,
nsISupportsArray* aRules,
@ -1411,6 +1413,8 @@ StyleContextImpl::StyleContextImpl(nsIStyleContext* aParent,
mContent(),
mUserInterface()
{
MOZ_COUNT_CTOR(StyleContextImpl);
NS_INIT_REFCNT();
NS_IF_ADDREF(mPseudoTag);
NS_IF_ADDREF(mRules);
@ -1435,6 +1439,8 @@ StyleContextImpl::StyleContextImpl(nsIStyleContext* aParent,
StyleContextImpl::~StyleContextImpl()
{
MOZ_COUNT_DTOR(StyleContextImpl);
NS_ASSERTION((nsnull == mChild) && (nsnull == mEmptyChild), "destructing context with children");
if (mParent) {

View File

@ -192,6 +192,7 @@ protected:
#endif
};
MOZ_DECL_CTOR_COUNTER(StyleSetImpl);
StyleSetImpl::StyleSetImpl()
: mOverrideSheets(nsnull),
@ -200,11 +201,13 @@ StyleSetImpl::StyleSetImpl()
mRecycler(nsnull),
mFrameConstructor(nsnull)
{
MOZ_COUNT_CTOR(StyleSetImpl);
NS_INIT_REFCNT();
}
StyleSetImpl::~StyleSetImpl()
{
MOZ_COUNT_DTOR(StyleSetImpl);
NS_IF_RELEASE(mOverrideSheets);
NS_IF_RELEASE(mDocSheets);
NS_IF_RELEASE(mBackstopSheets);

View File

@ -39,9 +39,11 @@
#define REALLY_NOISY_FONTS
#endif
MOZ_DECL_CTOR_COUNTER(nsFontMetricsGTK);
nsFontMetricsGTK::nsFontMetricsGTK()
{
MOZ_COUNT_CTOR(nsFontMetricsGTK);
NS_INIT_REFCNT();
mDeviceContext = nsnull;
mFont = nsnull;
@ -66,6 +68,8 @@ nsFontMetricsGTK::nsFontMetricsGTK()
nsFontMetricsGTK::~nsFontMetricsGTK()
{
MOZ_COUNT_DTOR(nsFontMetricsGTK);
if (nsnull != mFont) {
delete mFont;
mFont = nsnull;
@ -95,7 +99,35 @@ nsFontMetricsGTK::~nsFontMetricsGTK()
}
#undef LOG_REFCNTS
#ifdef LOG_REFCNTS
extern "C" {
void __log_addref(void* p, int oldrc, int newrc);
void __log_release(void* p, int oldrc, int newrc);
}
nsrefcnt nsFontMetricsGTK::AddRef(void)
{
NS_PRECONDITION(PRInt32(mRefCnt) >= 0, "illegal refcnt");
__log_addref((void*) this, mRefCnt, mRefCnt + 1);
return ++mRefCnt;
}
nsrefcnt nsFontMetricsGTK::Release(void)
{
__log_release((void*) this, mRefCnt, mRefCnt - 1);
NS_PRECONDITION(0 != mRefCnt, "dup release");
if (--mRefCnt == 0) {
NS_DELETEXPCOM(this);
return 0;
}
return mRefCnt;
}
NS_IMPL_QUERY_INTERFACE1(nsFontMetricsGTK, nsIFontMetrics)
#else
NS_IMPL_ISUPPORTS1(nsFontMetricsGTK, nsIFontMetrics)
#endif
#ifdef FONT_SWITCHING

View File

@ -40,11 +40,11 @@ static NS_DEFINE_CID(kRegionCID, NS_REGION_CID);
gdk.height = ns.height; \
PR_END_MACRO
MOZ_DECL_CTOR(nsRenderingContextGTK);
MOZ_DECL_CTOR_COUNTER(nsRenderingContextGTK);
nsRenderingContextGTK::nsRenderingContextGTK()
{
MOZ_CTOR(nsRenderingContextGTK);
MOZ_COUNT_CTOR(nsRenderingContextGTK);
NS_INIT_REFCNT();
mFontMetrics = nsnull;
@ -65,7 +65,7 @@ nsRenderingContextGTK::nsRenderingContextGTK()
nsRenderingContextGTK::~nsRenderingContextGTK()
{
MOZ_DTOR(nsRenderingContextGTK);
MOZ_COUNT_DTOR(nsRenderingContextGTK);
// Destroy the State Machine
if (mStateCache)

View File

@ -48,8 +48,12 @@ protected:
NS_IMPL_ISUPPORTS1(DeviceContextImpl, nsIDeviceContext)
MOZ_DECL_CTOR_COUNTER(DeviceContextImpl);
DeviceContextImpl :: DeviceContextImpl()
{
MOZ_COUNT_CTOR(DeviceContextImpl);
NS_INIT_REFCNT();
mFontCache = nsnull;
mDevUnitsToAppUnits = 1.0f;
@ -75,6 +79,8 @@ static PRBool DeleteValue(nsHashKey* aKey, void* aValue, void* closure)
DeviceContextImpl :: ~DeviceContextImpl()
{
MOZ_COUNT_DTOR(DeviceContextImpl);
if (nsnull != mFontCache)
{
delete mFontCache;

View File

@ -59,7 +59,7 @@ static NS_DEFINE_IID(kIPresContextIID, NS_IPRESCONTEXT_IID);
static NS_DEFINE_IID(kLookAndFeelCID, NS_LOOKANDFEEL_CID);
static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID);
MOZ_DECL_CTOR(nsPresContext);
MOZ_DECL_CTOR_COUNTER(nsPresContext);
nsPresContext::nsPresContext()
: mDefaultFont("Times", NS_FONT_STYLE_NORMAL,
@ -73,7 +73,7 @@ nsPresContext::nsPresContext()
0,
NSIntPointsToTwips(10))
{
MOZ_CTOR(nsPresContext);
MOZ_COUNT_CTOR(nsPresContext);
NS_INIT_REFCNT();
mCompatibilityMode = eCompatibility_Standard;
mCompatibilityLocked = PR_FALSE;
@ -96,7 +96,7 @@ nsPresContext::nsPresContext()
nsPresContext::~nsPresContext()
{
MOZ_DTOR(nsPresContext);
MOZ_COUNT_DTOR(nsPresContext);
mShell = nsnull;
Stop();

View File

@ -59,7 +59,7 @@ static NS_DEFINE_IID(kIPresContextIID, NS_IPRESCONTEXT_IID);
static NS_DEFINE_IID(kLookAndFeelCID, NS_LOOKANDFEEL_CID);
static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID);
MOZ_DECL_CTOR(nsPresContext);
MOZ_DECL_CTOR_COUNTER(nsPresContext);
nsPresContext::nsPresContext()
: mDefaultFont("Times", NS_FONT_STYLE_NORMAL,
@ -73,7 +73,7 @@ nsPresContext::nsPresContext()
0,
NSIntPointsToTwips(10))
{
MOZ_CTOR(nsPresContext);
MOZ_COUNT_CTOR(nsPresContext);
NS_INIT_REFCNT();
mCompatibilityMode = eCompatibility_Standard;
mCompatibilityLocked = PR_FALSE;
@ -96,7 +96,7 @@ nsPresContext::nsPresContext()
nsPresContext::~nsPresContext()
{
MOZ_DTOR(nsPresContext);
MOZ_COUNT_DTOR(nsPresContext);
mShell = nsnull;
Stop();

View File

@ -1390,6 +1390,8 @@ static PRBool HashStyleRule(nsISupports* aRule, void* aData)
return PR_TRUE;
}
MOZ_DECL_CTOR_COUNTER(StyleContextImpl);
StyleContextImpl::StyleContextImpl(nsIStyleContext* aParent,
nsIAtom* aPseudoTag,
nsISupportsArray* aRules,
@ -1411,6 +1413,8 @@ StyleContextImpl::StyleContextImpl(nsIStyleContext* aParent,
mContent(),
mUserInterface()
{
MOZ_COUNT_CTOR(StyleContextImpl);
NS_INIT_REFCNT();
NS_IF_ADDREF(mPseudoTag);
NS_IF_ADDREF(mRules);
@ -1435,6 +1439,8 @@ StyleContextImpl::StyleContextImpl(nsIStyleContext* aParent,
StyleContextImpl::~StyleContextImpl()
{
MOZ_COUNT_DTOR(StyleContextImpl);
NS_ASSERTION((nsnull == mChild) && (nsnull == mEmptyChild), "destructing context with children");
if (mParent) {

View File

@ -192,6 +192,7 @@ protected:
#endif
};
MOZ_DECL_CTOR_COUNTER(StyleSetImpl);
StyleSetImpl::StyleSetImpl()
: mOverrideSheets(nsnull),
@ -200,11 +201,13 @@ StyleSetImpl::StyleSetImpl()
mRecycler(nsnull),
mFrameConstructor(nsnull)
{
MOZ_COUNT_CTOR(StyleSetImpl);
NS_INIT_REFCNT();
}
StyleSetImpl::~StyleSetImpl()
{
MOZ_COUNT_DTOR(StyleSetImpl);
NS_IF_RELEASE(mOverrideSheets);
NS_IF_RELEASE(mDocSheets);
NS_IF_RELEASE(mBackstopSheets);

View File

@ -1390,6 +1390,8 @@ static PRBool HashStyleRule(nsISupports* aRule, void* aData)
return PR_TRUE;
}
MOZ_DECL_CTOR_COUNTER(StyleContextImpl);
StyleContextImpl::StyleContextImpl(nsIStyleContext* aParent,
nsIAtom* aPseudoTag,
nsISupportsArray* aRules,
@ -1411,6 +1413,8 @@ StyleContextImpl::StyleContextImpl(nsIStyleContext* aParent,
mContent(),
mUserInterface()
{
MOZ_COUNT_CTOR(StyleContextImpl);
NS_INIT_REFCNT();
NS_IF_ADDREF(mPseudoTag);
NS_IF_ADDREF(mRules);
@ -1435,6 +1439,8 @@ StyleContextImpl::StyleContextImpl(nsIStyleContext* aParent,
StyleContextImpl::~StyleContextImpl()
{
MOZ_COUNT_DTOR(StyleContextImpl);
NS_ASSERTION((nsnull == mChild) && (nsnull == mEmptyChild), "destructing context with children");
if (mParent) {

View File

@ -192,6 +192,7 @@ protected:
#endif
};
MOZ_DECL_CTOR_COUNTER(StyleSetImpl);
StyleSetImpl::StyleSetImpl()
: mOverrideSheets(nsnull),
@ -200,11 +201,13 @@ StyleSetImpl::StyleSetImpl()
mRecycler(nsnull),
mFrameConstructor(nsnull)
{
MOZ_COUNT_CTOR(StyleSetImpl);
NS_INIT_REFCNT();
}
StyleSetImpl::~StyleSetImpl()
{
MOZ_COUNT_DTOR(StyleSetImpl);
NS_IF_RELEASE(mOverrideSheets);
NS_IF_RELEASE(mDocSheets);
NS_IF_RELEASE(mBackstopSheets);

View File

@ -49,6 +49,7 @@ public:
gint mToken;
EventQueueToken *next;
};
EventQueueToken::EventQueueToken(const nsIEventQueue *aQueue, const gint aToken) {
mQueue = aQueue;
mToken = aToken;
@ -64,13 +65,16 @@ public:
private:
EventQueueToken *mHead;
};
EventQueueTokenQueue::EventQueueTokenQueue() {
mHead = 0;
}
EventQueueTokenQueue::~EventQueueTokenQueue() {
NS_ASSERTION(!mHead, "event queue token deleted when not empty");
// and leak. it's an error, anyway
}
void EventQueueTokenQueue::PushToken(nsIEventQueue *aQueue, gint aToken) {
EventQueueToken *newToken = new EventQueueToken(aQueue, aToken);
NS_ASSERTION(newToken, "couldn't allocate token queue element");
@ -79,6 +83,7 @@ void EventQueueTokenQueue::PushToken(nsIEventQueue *aQueue, gint aToken) {
mHead = newToken;
}
}
PRBool EventQueueTokenQueue::PopToken(nsIEventQueue *aQueue, gint *aToken) {
EventQueueToken *token, *lastToken;
PRBool found = PR_FALSE;
@ -104,6 +109,8 @@ PRBool EventQueueTokenQueue::PopToken(nsIEventQueue *aQueue, gint *aToken) {
return found;
}
MOZ_DECL_CTOR_COUNTER(nsAppShell);
//-------------------------------------------------------------------------
//
// nsAppShell constructor
@ -111,6 +118,7 @@ PRBool EventQueueTokenQueue::PopToken(nsIEventQueue *aQueue, gint *aToken) {
//-------------------------------------------------------------------------
nsAppShell::nsAppShell()
{
MOZ_COUNT_CTOR(nsAppShell);
NS_INIT_REFCNT();
mDispatchListener = 0;
mLock = PR_NewLock();
@ -127,6 +135,7 @@ nsAppShell::nsAppShell()
//-------------------------------------------------------------------------
nsAppShell::~nsAppShell()
{
MOZ_COUNT_DTOR(nsAppShell);
PR_DestroyLock(mLock);
delete mEventQueueTokens;
}
@ -136,7 +145,35 @@ nsAppShell::~nsAppShell()
// nsISupports implementation macro
//
//-------------------------------------------------------------------------
#ifdef LOG_REFCNTS
extern "C" {
void __log_addref(void* p, int oldrc, int newrc);
void __log_release(void* p, int oldrc, int newrc);
}
nsrefcnt nsAppShell::AddRef(void)
{
NS_PRECONDITION(PRInt32(mRefCnt) >= 0, "illegal refcnt");
__log_addref((void*) this, mRefCnt, mRefCnt + 1);
return ++mRefCnt;
}
nsrefcnt nsAppShell::Release(void)
{
__log_release((void*) this, mRefCnt, mRefCnt - 1);
NS_PRECONDITION(0 != mRefCnt, "dup release");
if (--mRefCnt == 0) {
NS_DELETEXPCOM(this);
return 0;
}
return mRefCnt;
}
NS_IMPL_QUERY_INTERFACE1(nsAppShell, nsIAppShell)
#else
NS_IMPL_ISUPPORTS1(nsAppShell, nsIAppShell)
#endif
//-------------------------------------------------------------------------
NS_IMETHODIMP nsAppShell::SetDispatchListener(nsDispatchListener* aDispatchListener)

View File

@ -19,6 +19,7 @@
#include "nscore.h" // needed for 'nsnull'
#include "nsToolkit.h"
MOZ_DECL_CTOR_COUNTER(nsToolkit);
//-------------------------------------------------------------------------
//
@ -27,6 +28,7 @@
//-------------------------------------------------------------------------
nsToolkit::nsToolkit()
{
MOZ_COUNT_CTOR(nsToolkit);
NS_INIT_REFCNT();
mSharedGC = nsnull;
}
@ -38,6 +40,7 @@ nsToolkit::nsToolkit()
//-------------------------------------------------------------------------
nsToolkit::~nsToolkit()
{
MOZ_COUNT_DTOR(nsToolkit);
if (mSharedGC)
gdk_gc_unref(mSharedGC);
}

View File

@ -30,8 +30,39 @@
#include "nsIPref.h"
#endif
#ifdef NOISY_WIDGET_LEAKS
static PRInt32 gNumWidgets;
#endif
// nsBaseWidget
#ifdef LOG_REFCNTS
extern "C" {
void __log_addref(void* p, int oldrc, int newrc);
void __log_release(void* p, int oldrc, int newrc);
}
nsrefcnt nsBaseWidget::AddRef(void)
{
NS_PRECONDITION(PRInt32(mRefCnt) >= 0, "illegal refcnt");
__log_addref((void*) this, mRefCnt, mRefCnt + 1);
return ++mRefCnt;
}
nsrefcnt nsBaseWidget::Release(void)
{
__log_release((void*) this, mRefCnt, mRefCnt - 1);
NS_PRECONDITION(0 != mRefCnt, "dup release");
if (--mRefCnt == 0) {
NS_DELETEXPCOM(this);
return 0;
}
return mRefCnt;
}
NS_IMPL_QUERY_INTERFACE1(nsBaseWidget, nsIWidget)
#else
NS_IMPL_ISUPPORTS1(nsBaseWidget, nsIWidget)
#endif
// nsBaseWidget::Enumerator
@ -43,6 +74,9 @@ NS_IMPL_ISUPPORTS2(nsBaseWidget::Enumerator, nsIBidirectionalEnumerator, nsIEnum
// nsBaseWidget constructor
//
//-------------------------------------------------------------------------
MOZ_DECL_CTOR_COUNTER(nsBaseWidget);
nsBaseWidget::nsBaseWidget()
: mClientData(nsnull)
, mEventCallback(nsnull)
@ -65,6 +99,12 @@ nsBaseWidget::nsBaseWidget()
#endif
, mZIndex(0)
{
MOZ_COUNT_CTOR(nsBaseWidget);
#ifdef NOISY_WIDGET_LEAKS
gNumWidgets++;
printf("WIDGETS+ = %d\n", gNumWidgets);
#endif
NS_NewISupportsArray(getter_AddRefs(mChildren));
NS_INIT_REFCNT();
@ -78,6 +118,12 @@ nsBaseWidget::nsBaseWidget()
//-------------------------------------------------------------------------
nsBaseWidget::~nsBaseWidget()
{
MOZ_COUNT_DTOR(nsBaseWidget);
#ifdef NOISY_WIDGET_LEAKS
gNumWidgets--;
printf("WIDGETS- = %d\n", gNumWidgets);
#endif
NS_IF_RELEASE(mMenuListener);
#ifdef LOSER
NS_IF_RELEASE(mVScrollbar);