• 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: autorelease pool
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: autorelease pool


  • Subject: Re: autorelease pool
  • From: Mike Abdullah <email@hidden>
  • Date: Tue, 23 Oct 2007 19:18:23 +0100

In the code you've just posted, NSAutoreleasePool is not used in any way for your string.

The sequence of alloc, init, and release does not use the autorelease pool since no -autorelease message is ever sent. Instead it does exactly as written:

1. Creates a new string object with a retain count of 1.
2. Releases the string so it has a retain count of 0.
3. Deallocates the memory used by the string since it has a retain count of 1.


Mike.

P.S. Normally in Cocoa you use lowercase to start a variable name. i.e.

NSString *line

On 23 Oct 2007, at 18:50, Erfan Aleemullah wrote:

I was wondering how this works and what happens if the retain count reaches
0 but the object wasn't part of a autorelease pool ?
*Example:*


NS* String Line = [NSString alloc] init];

.. random code ..

[Line release];

Now, what happens if the retain count is 1 and if its 0 for NSString Line ?
?


How should I use an autorelease pool to actually deallocate the memory used
by Line ?
_______________________________________________


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


  • Follow-Ups:
    • Re: autorelease pool
      • From: "Erfan Aleemullah" <email@hidden>
References: 
 >autorelease pool (From: "Erfan Aleemullah" <email@hidden>)

  • Prev by Date: Re: Window/View Size Constraining
  • Next by Date: Re: will/didChangeValueForKey: Real World Usage
  • Previous by thread: autorelease pool
  • Next by thread: Re: autorelease pool
  • Index(es):
    • Date
    • Thread