Re: monitoring retainCount
Re: monitoring retainCount
- Subject: Re: monitoring retainCount
- From: Phill Kelley <email@hidden>
- Date: Thu, 27 May 2004 12:49:41 +1000
At 01:12 +0200 27/05/2004, Stefan Fisk wrote:
>
i think you all are missing the point, i want to monitor the retain
>
count in code, so that i can know when the objects i've created get
>
destroyed, without polling each pass through the runloop etc.. what
>
you're suggesting are debugging aids, i want to be notified atleast
>
every time retainCount changes, preferably only when it reaches 0, and
>
it should work while deployed on "vanilla" installs of os x..
Given that your objects inherit from NSObject which is where retain,
release and autorelease originate, simply override those methods in any
objects where you wish to monitor what is going on. For example:
- (id)retain
{
NSLog(@"%@ sent retain, count=%d",[self className],[self retainCount]+1);
return [super retain];
}
If you add a an instance variable to your class to count the autorelease
messages, you can also track the projected retain count (ie, what will
happen once the autorelease pool is popped).
If you want to know when an object is destroyed, also override dealloc.
Does that help?
Regards, Phill
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.