Re: if statement causing 32 Byte leak?
Re: if statement causing 32 Byte leak?
- Subject: Re: if statement causing 32 Byte leak?
- From: Joar Wingfors <email@hidden>
- Date: Sun, 10 Jan 2010 09:43:40 -0800
On 10 jan 2010, at 09.13, Glenn L. Austin wrote:
> [pObj release]; // <-- This should assert in a debug context, since it is already in the current autorelease pool.
There is nothing wrong with releasing objects that have been added to autorelease pools per se, what could be considered incorrect in this line of code is the ordering of the memory management method calls. They should ideally be called and nested in a logical order where the sum of all current and "future" calls to memory management methods never end up in the negative (unless I forget some use case where that is needed?). At least in theory it would probably be possible to assert that this holds true.
> // [pObj autorelease] should also probably assert, since it is now in the current autorelease pool twice...
Again, there's nothing wrong with calling autorelease more than once on an object before the pool is popped (as long as the calls to autorelease is eventually balanced by calls to retain). Like above, I'd still call it a bad idea to call these methods "out of order".
> What I ended up doing is progressively creating NSAutoreleasePools, running the code from that routine, then draining that pool until I found the culprit. Oh the joys of working on a large project with programmers of varying Cocoa skill levels.
I would have suggested that you use the Object Alloc tool in Instruments which can be configured to show every alloc, retain, autorelease, release and dealloc event for any object. While not as precise and direct as what you suggested, it is a very easy and powerful way to troubleshoot this kind of issue. You owe it to yourself to make sure you understand how to use Instruments in this way.
j o a r
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden