Having trouble with a leaky bit of code

Discussion in 'iOS Programming' started by jeremyapp, Aug 23, 2009.

  1. jeremyapp macrumors newbie

    Apr 30, 2008
    Hey everyone,

    I have a bit of code that is leaking and I can't seem to figure out why.

    I have an XML Parser, and here's one of the snippets from its didEndElement method:

    else if([elementName isEqualToString:@"link"])
    		NSString *link = [currentAttribute stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
    		[tempElement setLink:link];
    CurrentAttribute is an NSMutableString that I clear out every time I encounter a new object. tempElement is a custom object that I use to store parsed values.

    I use the stringByReplacingOccurencesOfString method to remove spaces from links that I pull from an RSS feed.

    Doing this should return an autoreleased object, right?

    It seems this bit of code leaks though. Any thoughts?
  2. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    Remember that the leaks tool doesn't tell you where leaks occur. It tells you where an object that is leaked was created. So those lines you show are where the object was created, not where it leaked.

    Also, remember that because of common use of collections classes you can have the leaks tool show you a large number of leaks that really are a single leak. If you leak an array that holds a hundred other objects all the objects will show as leaked. If you fix the leak of the array then all the other objects won't leak.

Share This Page