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

substringWithRange: memory leak problem


  • Subject: substringWithRange: memory leak problem
  • From: John Clayton <email@hidden>
  • Date: Mon, 26 Sep 2005 21:33:39 -0400

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: substringWithRange: memory leak problem
      • From: j o a r <email@hidden>
    • Re: substringWithRange: memory leak problem
      • From: Jonathan del Strother <email@hidden>
  • Prev by Date: Re: Does floorf work?
  • Next by Date: NSTextInput, multi-character marks, and the cursor position
  • Previous by thread: Re: Does floorf work?
  • Next by thread: Re: substringWithRange: memory leak problem
  • Index(es):
    • Date
    • Thread