• 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: NSString's "mutableCopy" creating a leak?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSString's "mutableCopy" creating a leak?


  • Subject: Re: NSString's "mutableCopy" creating a leak?
  • From: Randall Meadows <email@hidden>
  • Date: Wed, 1 Oct 2008 14:04:36 -0600

[Oops, I realized I didn't Reply-All and include the list in my first answer.]

On Oct 1, 2008, at 1:45 PM, Christopher J Kemsley wrote:

I do better than that - on the dealloc call, my code explicitly deallocates it.

Meaning, I assume, in this containing class's -dealloc, you call [editedRowName dealloc]? I don't think you want to do that; I don't think you're supposed to call -dealloc yourself, but rather -release, and let the system call -dealloc if necessary.


On Oct 1, 2008, at 12:44 PM, Randall Meadows wrote:
On Oct 1, 2008, at 1: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.

OK, good...

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?

Do you [auto]release "editedRowName", the mutable instance? By using the -mutableCopy: method, you are responsible for releasing the result explicitly.
_______________________________________________

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: 
 >NSString's "mutableCopy" creating a leak? (From: Christopher J Kemsley <email@hidden>)

  • Prev by Date: Re: NSString's "mutableCopy" creating a leak?
  • Next by Date: Re: NSString's "mutableCopy" creating a leak?
  • Previous by thread: Re: NSString's "mutableCopy" creating a leak?
  • Next by thread: Re: NSString's "mutableCopy" creating a leak?
  • Index(es):
    • Date
    • Thread