Re: AutoreleasePools and Threads
Re: AutoreleasePools and Threads
- Subject: Re: AutoreleasePools and Threads
- From: Matt Neuburg <email@hidden>
- Date: Tue, 9 Jul 2002 06:41:52 -0700
On Wed, 3 Jul 2002 21:04:54 -0700, Kevin Perry <email@hidden> said:
>
Hi, in an application that I'm working on, there's a method detached in
>
another thread. Of course, in that method, an autorelease pool is
>
created as per necessity. However, in that method, there's a while()
>
loop that repeats indefinitely that creates a lot of autoreleased
>
objects that will never get released because the pool is released after
>
the while() loop. I've got a half-decent solution to create another
>
autorelease pool at the begin of the while loop and to release it at the
>
end of the loop. However, I don't believe this frequent allocing and
>
releasing of objects is as efficient as it could be. Is there a better
>
solution for this that I have failed to notice?
Between the two ways of managing an object's lifetime - alloc/release or
pool-alloc/autorelease/pool-release - I really don't see a difference. They
are both of about the same efficiency. They both use the device of raising
and lowering an object's retain count and letting Cocoa free it when the
retain count hits zero. You are allocing and releasing objects either way;
if you don't want that to happen, don't make so many objects (or don't use
Cocoa memory management at all! :-)). Your secondary pool prevents memory
usage from building up in the background, and that's all that matters. m.
--
matt neuburg, phd = email@hidden,
http://www.tidbits.com/matt
pantes anthropoi tou eidenai oregontai phusei
Subscribe to TidBITS! It's free and smart.
http://www.tidbits.com/
_______________________________________________
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.