• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Still learning about NSAutoReleasePool
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Still learning about NSAutoReleasePool


  • Subject: Re: Still learning about NSAutoReleasePool
  • From: Eric Brunstad <email@hidden>
  • Date: Sat, 11 Jun 2005 11:58:04 -0400

Hi,

On Jun 11, 2005, at 8:46 AM, Theodore H. Smith wrote:

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.

You are wrong. Here's what's really happening:

1) windowControllerDidLoadNib is called and an autorelease pool is put into effect.
2) -stringWithCString returns a NSString which is added to the autorelease pool.
3) your subsequent calls to -autorelease do nothing because the object is already in the autorelease pool.
4) -windowControllerDidLoadNib ends and the autorelease pool is released, therefore deleting the string that you created.


Eric Brunstad
Mind Sprockets Software
email@hidden
www.mindsprockets.com

_______________________________________________
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


  • Follow-Ups:
    • Re: Still learning about NSAutoReleasePool
      • From: Jim Correia <email@hidden>
References: 
 >Still learning about NSAutoReleasePool (From: "Theodore H. Smith" <email@hidden>)

  • Prev by Date: Re: Still can't figure out this overrelease bug
  • Next by Date: Re: need help with linking error
  • Previous by thread: Re: Still learning about NSAutoReleasePool
  • Next by thread: Re: Still learning about NSAutoReleasePool
  • Index(es):
    • Date
    • Thread