Re: I don't understand why this is leaking...
Re: I don't understand why this is leaking...
- Subject: Re: I don't understand why this is leaking...
- From: Negm-Awad Amin <email@hidden>
- Date: Tue, 12 Aug 2008 10:50:31 +0200
Am Di,12.08.2008 um 10:42 schrieb Gerriet M. Denkmann:
On 9 Aug 2008, at 17:39:20 -0600, Jonathan deWerd <email@hidden
>wrote:
On Aug 9, 2008, at 4:48 PM, Cate Tony wrote:
This code is leaking:
- (void)saveItemExtensions:(id)sender
{
NSMutableString* itemExtensionsFilePath = [NSMutableString
stringWithString:@"~/Library/Preferences/MyApp/extensions.abc"];
NSDictionary* extensions = [NSDictionary dictionaryWithDictionary:
[itemDataSource itemExtensions]];
[itemExtensionsFilePath setString:[itemExtensionsFilePath
stringByExpandingTildeInPath]];
[[NSArchiver archivedDataWithRootObject:extensions]
itemExtensionsFilePath atomically: YES];
}
- (void)encodeWithCoder:(NSCoder *)coder
{
[coder encodeObject: string1];
[coder encodeObject: string2];
[coder encodeObject: string3];
[coder encodeObject: string4];
[coder encodeObject: string5];
[coder encodeObject: string6];
[coder encodeObject: string7];
[coder encodeObject: string8];
}
According to MallocDebug, the leak is in the encodeWithCoder method.
Things I've tried:
1 [coder encodeObject: [string1 autorelease]]; Which, of course,
caused a crash
2 [coder encodeObject: [string1 copy]]; no diff
3 [coder encodeObject: [[string1 copy] autorelease]]; no diff
4 Drinking beer...
Can anyone explain this to me?
Tony
What is coder? It could be that coder is deferring the encoding
(saving copies of string*), and then the coder itself is never
getting
released. Have Instruments make sure that the coder is actually going
away after the encoding is done. Also check to make sure the encoded
data is going away when it is no longer needed. Sometimes the leak
isn't exactly where MallocDebug says the object was allocated: -
retain
increments the retain count as surly as -alloc. What do the
individual
string* histories look like in Instruments? Speaking of Instruments,
could you give us (not the mailing list, I don't think it allows
attachments, but you could email me separately) an instruments
session
to look at? It would greatly facilitate proceedings :)
Also, why are you using non-keyed encoding? -encodeObject:forKey: is
the preferred way of doing things nowadays...
Well, it may be the preferred way, but it is not always the best,
nor even the correct way.
Two reasons:
1. the resulting files are much bigger
2. NSKeyedArchiver can only store certain strings (tested in
10.4.11), which makes it absolutely unusable for the storage of
strings if the possible values are not known in advance.
Do you have an example for that?
Amin
Kind regards,
Gerriet.
_______________________________________________
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
Amin Negm-Awad
email@hidden
_______________________________________________
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