Re: Autorelease Question
Re: Autorelease Question
- Subject: Re: Autorelease Question
- From: Luke the Hiesterman <email@hidden>
- Date: Wed, 19 Nov 2008 15:44:24 -0800
It's simply not true that you have "no idea" when an object will be
autoreleased. If you're on the main thread, you know that it will be
released at the end of the runloop, and you know that your current
method will return to its caller within the current runloop.
Furthermore, you know that if you call a method from your method, that
it will be executed within the current runloop. Unless you're dealing
with asynchronous calls, it's actually fairly easy to know if you're
going to fall out of the current runloop or not.
Luke
On Nov 19, 2008, at 3:31 PM, Kyle Sluder wrote:
On Wed, Nov 19, 2008 at 6:17 PM, Filip van der Meeren
<email@hidden> wrote:
If you wait until the end of your method to autorelease the object,
you are
leaving a whole range of possible memoryleaks open, since every
call you
make between the allocation and release is a call that might throw an
exception (and we all know Objective-C uses memoryjumps from C).
Gah! You have no idea when an autoreleased object is going to be
released. What if a method call you make in between autoreleasing the
object and really not needing it anymore hits the top of the runloop?
Boom, your autoreleased object is gone. As the documentation states,
only use autorelease to signal that you no longer need an object.
As for exceptions, that's why we have @finally blocks. Though since
exceptions in Cocoa are supposed to be reserved for programmer errors,
I would not worry all that much about exceptions and memory leaks.
--Kyle Sluder
_______________________________________________
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
_______________________________________________
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