Re: NSString's "mutableCopy" creating a leak?
Re: NSString's "mutableCopy" creating a leak?
- Subject: Re: NSString's "mutableCopy" creating a leak?
- From: Corbin Dunn <email@hidden>
- Date: Wed, 01 Oct 2008 14:13:53 -0700
On Oct 1, 2008, at 12:34 PM, Christopher J Kemsley wrote:
I'm writing a program that, in one table view, has the following code:
id receivedName = [theDatabase itemAtIndex:editedRow] ;
editedRowName = [receivedName mutableCopy] ;
[receivedName release];
where "editedRowName" is defined as an NSMutableString.
[theDatabase itemAtIndex:editedRow]
Asks my database to return item "editedRow." The object at that
index is an NSString. For this function, the database would return
[theStringHere retain]
My code needs a mutable version of this string, so I make a
mutableCopy of it and release the old one, as to prevent a memory
leak.
However, when I do a "Run with performance tool: Leaks", it tells me
that, ever time this part of the code runs, it leaks a
"GeneralBlock-32" with the following information:
Category: CFString (store)
Event Type: Malloc
Responsible Library: Foundation
Responsible Caller: -[NSCFString mutableCopyWithZone:]
Does anybody know where this leak is coming from?
The other replies covered most the basics. If (after you read the
memory management guideline) you still have a leak, turn on Record
Reference Counts so you can see all the retain/releases/autoreleased
on the object. You can then figure out where you haven't released it
but should have. Effectively, you are doing the opposite of what is
mentioned here:
http://www.corbinstreehouse.com/blog/index.php/2007/10/instruments-on-leopard-how-to-debug-those-random-crashes-in-your-cocoa-app/
which is telling you how to find an over-release (one too many
releases), but the concept is similar (except, you don't need to turn
on zombies).
corbin
_______________________________________________
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