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

Re: NSMutableDictionary autorelease chrashes application


  • Subject: Re: NSMutableDictionary autorelease chrashes application
  • From: Trygve Inda <email@hidden>
  • Date: Fri, 18 Jul 2008 14:48:15 +0000
  • Thread-topic: NSMutableDictionary autorelease chrashes application

> Hi!
>
> I'm a rookie with Cocoa development, please excuse if this question is
> stupid, but I'm struck with memory management (an even Aaron's book
> doesn't help me):
>
> In a method I use a (temporary) dictionary "vAttributes" to read an
> object from an instance variable "vColors" (a dictionary, too):
>
> - (NSString *)descriptionByColorCode:(int)colorCode
> {
> NSMutableDictionary *vAttributes = [[NSMutableDictionary alloc] init];
>
> vAttributes = [vColors objectForKey:[NSNumber
> numberWithInt:colorCode]];
> return [vAttributes objectForKey:@"colorDescription"];
> }
>
> It is my understanding, that after the "alloc" message "vAttributes"'
> retain count is 1 and as I use it in the return statement, a "release"
> out of question. So "vAttributes" should receive an "autorelease"
> message before the return statement to avoid an object leak, but than
> the application crashes after the first invokation of this method.
>
> ... where am I wrong?

If you autorelease this, then as soon as you fall back into your run loop,
the object will be released. What happens to the dictionary after it is
returned? Perhaps the calling code should be responsible for releasing this.

Trygve


_______________________________________________

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

References: 
 >NSMutableDictionary autorelease chrashes application (From: Matthias Arndt <email@hidden>)

  • Prev by Date: Re: Controlling Preferences on iPhone
  • Next by Date: RE: Image name for drag and drop from Safari
  • Previous by thread: Re: NSMutableDictionary autorelease chrashes application
  • Next by thread: Controlling Preferences on iPhone
  • Index(es):
    • Date
    • Thread