• 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: I don't understand why this is leaking...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: I don't understand why this is leaking...


  • Subject: Re: I don't understand why this is leaking...
  • From: Jonathan deWerd <email@hidden>
  • Date: Sat, 9 Aug 2008 17:39:20 -0600

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...



_______________________________________________

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:
@gmail.com


This email sent to email@hidden

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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: 
 >I don't understand why this is leaking... (From: Cate Tony <email@hidden>)

  • Prev by Date: compiling a bundle on intel?
  • Next by Date: Re: Custom URL Handling
  • Previous by thread: I don't understand why this is leaking...
  • Next by thread: Re: I don't understand why this is leaking...
  • Index(es):
    • Date
    • Thread