开发者

Memory Leak from NSXMLParser

开发者 https://www.devze.com 2023-03-06 17:08 出处:网络
im running cocos2d with levelSVG, a SVG Parsing system from Sapus Media. I\'m using the parse system, which works as predicted, but im having a few problems with memory leaks associated with the NSXML

im running cocos2d with levelSVG, a SVG Parsing system from Sapus Media.

I'm using the parse system, which works as predicted, but im having a few problems with memory leaks associated with the NSXMLParser.

The Memory Leaks give a consistent dro开发者_JS百科p in fps over a timespan of 5 minutes and render the application useless at 12fps at the end of this timeframe.

I have removed all my particlesystems and other potentially leaky objects and the leak still exists..

Running the Memory Leak Tool:

3 Leaking Objects Detected:

GeneralBlock-512

GeneralBlock-512

NSConcreteMapTable

They link to:

*

NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:url];  

        [parser setDelegate:self];
        [parser setShouldProcessNamespaces:NO];
        [parser setShouldReportNamespacePrefixes:NO];
        [parser setShouldResolveExternalEntities:NO];
        [parser parse];

        NSError *parseError = [parser parserError];
        if(parseError) {
            SVGLOG(@"Error parsing SVG file: %@", parseError);
        }

        [parser release];

As you can see, the object is released after the parsing has been completed.

Driving me bonkers, does anyone know whats happening?


Okay, after a bit of research I found a bug in the NSXMLParser when using the URL method as described above.

NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:url]

By changing this to:

NSData *xml = [NSData dataWithContentsOfURL:url];            
NSXMLParser *parser = [[NSXMLParser alloc] initWithData:xml];

This fixed the memory leak issue but still didnt account for the consistent drop of fps over the timeframe. I then found that my allocations of memory for a particular class, CCFollow was consistently increasing overtime on the memory-leak tool.

I then checked the code and I was running an infinite CCAction - CCFollow, within a repeating tick update method. This was the source of the memory drain. Removing it from the tick update method and moving it to an initialisation method fixed this problem.

0

精彩评论

暂无评论...
验证码 换一张
取 消