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

Re: NSMutableDictionary Leak


  • Subject: Re: NSMutableDictionary Leak
  • From: Dave DeLong <email@hidden>
  • Date: Fri, 28 Nov 2008 17:17:59 -0700

This may not fix your problem, but it doesn't look like you're using the convenience methods correctly.

NSMutableDictionary *tmp = [NSMutableDictionary dictionaryWithCapacity:4];

tmp comes back with a retain count of 1, but it is already autoreleased. You don't need to do any sort of releasing or autoreleasing yourself, UNLESS you also specifically retain it.

The same holds true with tmp2.  So you can do:

NSMutableDictionary *tmp = [NSMutableDictionary dictionaryWithCapacity:4];
NSMutableDictionary *tmp2 = [NSMutableDictionary dictionaryWithCapacity:4]; // or whatever
[tmp setObject:[NSDictionary dictionaryWithDictionary:tmp2] forKey:@"Data"];


Be aware, though, that you've got a dictionary that contains a dictionary that contains a dictionary. Is that what you're going for?

HTH,

Dave

On 28 Nov, 2008, at 5:04 PM, dct wrote:

I've started using Instruments/Leaks on a project that has been building and running as expected. It has identified a goodly number of CFDictionary leaks (a Malloc leak followed by an Autorelease leak) associated with lines that, in one typical case, reads:

[tmp setObject:[NSDictionary dictionaryWithDictionary:tmp2] forKey:@"Data"];

The MutableDictionary object "tmp" is instantiated at the beginning of this particular method by:

NSMutableDictionary *tmp = [[NSMutableDictionary dictionaryWithCapacity:4] autorelease];

Do I need to autorelease  a la:

[tmp setObject:[[NSDictionary dictionaryWithDictionary:tmp2] autorelease] forKey:@"Data"];

or is this a non-problem given that the reported Malloc leak is followed by an Autorelease leak?
_______________________________________________

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 Leak (From: dct <email@hidden>)

  • Prev by Date: Re: NSMutableDictionary Leak
  • Next by Date: Re: NSMutableDictionary Leak
  • Previous by thread: Re: NSMutableDictionary Leak
  • Next by thread: Re: NSMutableDictionary Leak
  • Index(es):
    • Date
    • Thread