0

Please see the image attached. If its not visible here is the code

- (void)startParsingData:(NSString *)xmlDataString
{
    NSLog(@"parser started");
    // allocate NSXMLParser
    NSLog(@"XML DATA equals %@", xmlDataString);
    NSData* xmlData=[xmlDataString dataUsingEncoding:NSUTF8StringEncoding];
    dataParser = [[NSXMLParser alloc] initWithData:xmlData];
    // assign delegate to parser
    dataParser.delegate = self;
    // parse data
    [dataParser parse];
    // release parser
    [dataParser release];
    // release data
    //[xmlData release];
}

The activity monitor shows that there is leak in the following line -

[dataParser parse];

I don't understand. Why? As I have released that object.

EDIT :

I changed the method to -

- (void)startParsingData:(NSString *)xmlDataString
{
    NSLog(@"parser started");
    // allocate NSXMLParser
    NSLog(@"XML DATA equals %@", xmlDataString);
    NSData* xmlData=[xmlDataString dataUsingEncoding:NSUTF8StringEncoding];
    [[NSURLCache sharedURLCache] setMemoryCapacity:0];
    [[NSURLCache sharedURLCache] setDiskCapacity:0];
    dataParser = [[NSXMLParser alloc] initWithData:xmlData];
    // assign delegate to parser
    dataParser.delegate = self;
    // parse data
    [dataParser parse];
    // release parser
    [dataParser release];
    // release data
    //[xmlData release];
}

Still the leak is there.

enter image description here

Vaibhav Tekam
  • 2,344
  • 3
  • 18
  • 27
  • 1
    Can you post the delegate methods as well please? Something inside the call to parse there is an element that isn't been cleaned up properly. It should be inside the delegate method – Totumus Maximus Aug 16 '12 at 10:02
  • You were correct. I see some allocated strings there, which are not released. I will release them and check again. – Vaibhav Tekam Aug 17 '12 at 05:19

1 Answers1

1

Try using:

[[NSURLCache sharedURLCache] setMemoryCapacity:0];
[[NSURLCache sharedURLCache] setDiskCapacity:0];
dataParser = [[NSXMLParser alloc] initWithContentsOfURL:URL];

It seems to stop the leaks for people on these questions:

Got memory leak problem when i used NSXMLParser same as SeismicXML Example

Can't find the leak in this Objective-C NSXMLParser code?

Community
  • 1
  • 1
Totumus Maximus
  • 7,543
  • 6
  • 45
  • 69
  • But in my case, I am not using URL, instead, I am passing NSData objects. Any idea, how to deal in that case. Or is it a bug? – Vaibhav Tekam Aug 16 '12 at 09:50
  • It should go the same way with your init I suppose. The main thing is probably that he has some data cached but never destroyed the moment you use this parser again and thus create a leak. – Totumus Maximus Aug 16 '12 at 09:51
  • You were correct. I see some allocated strings there, which are not released. I will release them and check again – Vaibhav Tekam Aug 23 '12 at 08:02