Re: NSMutableDictionary Leak
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