Re: [[Class alloc] init] preferable over [[Class instance] retain]?
Re: [[Class alloc] init] preferable over [[Class instance] retain]?
- Subject: Re: [[Class alloc] init] preferable over [[Class instance] retain]?
- From: Matt Neuburg <email@hidden>
- Date: Thu, 11 Mar 2010 08:48:03 -0800
- Thread-topic: [[Class alloc] init] preferable over [[Class instance] retain]?
On Tue, 9 Mar 2010 23:58:55 +0000, Jeff Laing <email@hidden>
said:
>The upshot was that apparently the iPhone developers like you to avoid the use
of autorelease pools where possible. One hidden difference in the above is that
in the first case you have (probably) populated the autorelease pool and in the
other you (probably) haven't.
I don't think it's accurate to say that you're supposed to avoid autorelease
pools on iPhone. The quoted statement seems to me to misrepresent the docs,
the comments from Apple in their examples, and so forth.
What they're trying to say, it seems to me, is just the opposite: you should
*use* autorelease pools on iPhone. What you should *not* do, if you can
avoid it, is rely on the *implicit* autorelease pool.
In other words, the problem with this:
NSString* s = [NSString stringWithFormat...];
...is that you don't know when s will be released. In some situations, you
can easily fill up a lot of memory before the implicit autorelease pool is
drained. One solution is to create an autorelease pool and release it
explicitly. This puts *you* in charge of marking objects for release. In
other words, to alloc and release an autorelease pool is (or can be) just as
good as alloc and release of individual objects. And it takes care of the
problem where autoreleased objects are inevitable or are created behind your
back.
m.
--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
http://www.tidbits.com/matt/default.html#applescriptthings
_______________________________________________
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