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

Re: NSAutoreleasePool


  • Subject: Re: NSAutoreleasePool
  • From: Clark Cox <email@hidden>
  • Date: Wed, 14 Jan 2004 10:09:02 -0500

On Jan 14, 2004, at 07:44, Amit Sadana wrote:

> Consider the following sample code:
>
> -(void) myMethod
>
> {
> NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
> // lot of stuff going on here with lot of memory allocations
> [pool release];
> }
>
>
>
> 1. Do I have to explicitly do an autorelease to ensure that is handled
> by my current NSAutorelease pool

Anything that is autoreleased in your method (whether it be by you or
by some other method you call) will be sent a release message when you
release your pool.

>
> 2. What if I want to release some allocated memory on my own by doing
> an
> explicit [... release] call. I have observed this is not at all
> possible. It simply causes the application to crash. This holds true
> even if I am doing the allocation and release at a very deep nested
> level place in code called from a method (within NSAutorelease alloc
> and
> pool release block) from -myMethod

If something is already added to an autorelease pool, then calling
release will eventually end up releasing that object twice (i.e. once
for your explicit release call, and once for the pool). If you want
something to go away immediately, don't autorelease it.

--
Clark S. Cox III
email@hidden
http://homepage.mac.com/clarkcox3/
http://homepage.mac.com/clarkcox3/blog/B1196589870/index.html

[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: crash on quit
  • Next by Date: Get News Progammatically?
  • Previous by thread: NSAutoreleasePool
  • Next by thread: [ANN : my new application is out]
  • Index(es):
    • Date
    • Thread