Re: Still learning about NSAutoReleasePool
Re: Still learning about NSAutoReleasePool
- Subject: Re: Still learning about NSAutoReleasePool
- From: Prachi Gauriar <email@hidden>
- Date: Sat, 11 Jun 2005 12:47:49 -0400
On Jun 11, 2005, at 8:46 AM, Theodore H. Smith wrote:
OK, so assuming that, then it also appears that NSAutoReleasePool
does not check for overreleasing, when it actually could.
...
Basically, I'm wondering if I can subclass NSAutoReleasePool to be
a bit more stringent about what it accepts and rejects. At the
point above where all is not well, perhaps I can override some
methods to make NSAutoReleasePool complain that an object has been
over added?
I'm not sure that it's possible to do this in a good way.
Autorelease pools are just objects, and you can certainly have
several in your app at once (different nesting levels, different
threads, etc). As such, your pools would have to communicate with
each other so they could give an accurate count of how many times an
object had been autoreleased.
In addition, there's nothing wrong with over-autoreleasing as long as
you retain it before the pool releases its objects, i.e.
obj = [[Class new] autorelease];
[obj autorelease];
[obj retain];
[obj retain];
That said, I've never actually seen this in code, though it might
occur in some more complex interactions between methods.
Of course, none of this stuff is a big problem if you just learn the
relatively simple rules of reference counting in Cocoa:
Method Effect on reference count
-alloc* refCount = 1
-copy* refCount = 1
+new* refCount = 1
-retain refCount += 1
-release refCount -= 1
-autorelease refCount -= 1 "later"
-Prachi
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden