Re: In-loop releasing of objects does not free memory?
Re: In-loop releasing of objects does not free memory?
- Subject: Re: In-loop releasing of objects does not free memory?
- From: "Shawn Erickson" <email@hidden>
- Date: Wed, 13 Feb 2008 09:07:15 -0800
On Feb 13, 2008 8:57 AM, Shawn Erickson <email@hidden> wrote:
> On Feb 12, 2008 5:10 PM, John Terranova <email@hidden> wrote:
> > I guess I should have been more explicit and said to, first, verify
> > that retainCount > 1 with this type of NSLog(). Then, investigate why
> > retainCount > 1. If it is an autorelease, then "try wrapping the body
> > of the loop in an autorelease pool," if that is your chosen solution.
> > If there are no autoreleases (or not enough to account for the
> > retainCount), then you must "find" your missing auto/release to patch
> > the real leak.
>
> You assume the object accumulating is one that you can query the
> retainCount of. It could be something created by the framework in
> response to -[NSString initWithContentsOfFile:].
>
> IMHO it seldom a good idea to query and log retain counts in this way
> (it can easily mislead) instead use tools like ObjectAlloc and now
> Instruments to understand what is taking place.
I also meant to state that ideally you shouldn't make any assumptions
about what the framework will do (it may change on you in the future).
If you have a loop that logically has a good chance of causing a lot
of objects and/or large objects to be created before unwinding back up
to the runloop you should consider the use of a loop scoped
autorelease pool (assuming you aren't using GC, if you are using GC
consider using -[NSGarbageCollector collectIfNeeded]).
<http://developer.apple.com/documentation/Cocoa/Conceptual/GarbageCollection/Articles/gcEssentials.html#//apple_ref/doc/uid/TP40002452-SW7>
<http://developer.apple.com/documentation/Cocoa/Reference/NSGarbageCollector_class/Introduction/Introduction.html#//apple_ref/occ/instm/NSGarbageCollector/collectIfNeeded>
-Shawn
_______________________________________________
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