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

Re: newbie question


  • Subject: Re: newbie question
  • From: "Stephen Deken" <email@hidden>
  • Date: Fri, 10 Nov 2006 09:17:20 -0600

if i create a NSAutoreleasePool and add the dictionary to the pool,
it works fine:

You don't have to add the dictionary to the pool -- [NSMutableDictionary dictionaryWith...] does that for you. Creating the pool is all you need to do (and you usually don't need to do even that -- it's just that within your main() method, AppKit hasn't been able to create one yet).

such as  dictionaryWithCapacity: are deallocated automatically.
so why do i get this runtime error then?

They are deallocated automatically when the autorelease pool is released. Autorelease pools hold references to objects, and release all of them when the autorelease pool is released.

Saying this:

 NSMutableDictionary *m = [NSMutableDictionary dictionaryWithCapacity:1];

is equivalent to this:

 NSMutableDictionary *m = [NSMutableDictionary alloc];
 [m initWithCapacity:1];
 [m autorelease];

The [m autorelease] line adds the object to the current autorelease
pool.  In general, this is the only way that an object can be added to
an autorelease pool -- you should never add an object to a specific
autorelease pool.

Stephen Deken
email@hidden
_______________________________________________
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: newbie question
      • From: maximilian marcoll <email@hidden>
    • Re: Re: newbie question
      • From: "Shawn Erickson" <email@hidden>
References: 
 >newbie question (From: maximilian marcoll <email@hidden>)

  • Prev by Date: Re: newbie question
  • Next by Date: Re: Authorization code fails in Leopard
  • Previous by thread: Re: newbie question
  • Next by thread: Re: Re: newbie question
  • Index(es):
    • Date
    • Thread