Still learning about NSAutoReleasePool
Still learning about NSAutoReleasePool
- Subject: Still learning about NSAutoReleasePool
- From: "Theodore H. Smith" <email@hidden>
- Date: Sat, 11 Jun 2005 13:46:07 +0100
OK, I did this experiment with a new blank Cocoa NSDocument based
project.
I changed one method, this one below:
- (void)windowControllerDidLoadNib:(NSWindowController *) aController
{
[super windowControllerDidLoadNib:aController];
NSString* s = [NSString stringWithCString:"hello"];
[s autorelease];
[s autorelease];
[s autorelease];
}
I ran the project, and the project did not complain or crash. The
window was displayed just fine. Strange.
I'm assuming that the NSString* s actually got corrupted, but because
the behaviour is undefined upon corruption, it just so happened that
I was unlucky enough that no crash occurred. (I think it is a bad
thing for bugs to pass unseen, which is why I say unlucky).
OK, so assuming that, then it also appears that NSAutoReleasePool
does not check for overreleasing, when it actually could.
Let's step through this analytically:
* The NSString s, at first had a refcount of 1 when it was (within
stringWithCString's internals) created by alloc.
* The NSString s then was placed into an autorelease pool (within
stringWithCString's internals)
At this point, all is well. No no more references to the object
existed than it's refcount existed.
* The NSString s was then autoreleased by my bad code.
At this point, more refs in the autoreleasepool exist than the
refcount exists. All is not well.
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 quite happy to be told I've got all of this totally wrong, after
all I'm still learning the basics of Cocoa.
--
http://elfdata.com/plugin/ Industrial strength string processing,
made easy.
"All things are logical. Putting free-will in the slot for premises in
a logical system, makes all of life both understandable, and free."
_______________________________________________
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