• 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: substringWithRange: memory leak problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: substringWithRange: memory leak problem


  • Subject: Re: substringWithRange: memory leak problem
  • From: Jonathan del Strother <email@hidden>
  • Date: Tue, 27 Sep 2005 02:52:00 +0100

Are you later retaining myString anywhere? IIRC, MallocDebug only reports where the string was created, rather than where it's gotten retained...


On 27 Sep 2005, at 02:33, John Clayton wrote:

Hi,

MallocDebug is telling me I have a memory leak in some code like this:


- (void) parse:(NSString *)someString {
NSArray *myArray= [someString componentsSeparatedByString:@"\n"];
int i, count = [myArray count];
for(i = 0; i < count; i++) {
NSString *line = [myArray objectAtIndex:i];
NSString *slice = [line substringWithRange:someRange];
NSString *myString = [slice stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceCharacterSet]];
}


}

The leak is tracked down to a call graph like (inverted): substringWithRange: -> stringByTrimmingCharactersInSet

Now, as far as I can tell both of those methods return an autoreleased string. And, releasing or autoreleasing either of them actually does result in bad memory access.

Wow, stumped.

Any ideas? I can send an actual method if that helps, but it's a bit longer.

Thanks, cocoa-folk.

John

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40steelskies.com


This email sent to email@hidden


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: substringWithRange: memory leak problem
      • From: John Clayton <email@hidden>
References: 
 >substringWithRange: memory leak problem (From: John Clayton <email@hidden>)

  • Prev by Date: Re: CD: subclassing NSArrayController
  • Next by Date: Re: QTKit for creating movies
  • Previous by thread: substringWithRange: memory leak problem
  • Next by thread: Re: substringWithRange: memory leak problem
  • Index(es):
    • Date
    • Thread