Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-17-2010, 11:48 PM   #1 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 31
EthanK is on a distinguished road
Default Memory Leak Help?

I've got a memory leak that seems to be coming from my parser each time I run it, and I'm having a hard time understanding the issue! The memory leak was found with the leak performance tool.

In the header:
Code:
NSMutableString * currentNodeContent;
Starting my xml parsing element:

Code:
//----------------------------------------------
// Starting an Element
//----------------------------------------------
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
	if(qName) {
		elementName = qName;
	}
	
        //Only init a string if we are on the right element to build it.
	if ([elementName isEqualToString:@"missionname"])
		currentNodeContent = [[NSMutableString alloc] init];
Here is what happens as we collect characters.
Code:
//----------------------------------------------
// Finding characters during parse
//----------------------------------------------
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
	
	[currentNodeContent appendString:string];
	
}

Here is the ending element, where we save the string off to a new one and then release the temp one.

Code:
//----------------------------------------------
// Ending Element
//----------------------------------------------
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{	
	if(qName) {
		elementName = qName;
	}
	
	if([elementName isEqualToString:@"missionname"]){
		missionData[totalMissions].Name = [[NSMutableString alloc] init];
		missionData[totalMissions].Name = [currentNodeContent mutableCopy];
		[currentNodeContent release];
		currentNodeContent = nil;
	}
Pretty much when I stack trace it lights up everything in the above if statement for missionname. Even the simple appendstring gets a warning. Any thoughts? Is there anything I'm obviously doing wrong?
EthanK is offline   Reply With Quote
Old 08-18-2010, 01:04 AM   #2 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 386
SoulRed12 is on a distinguished road
Default

It's this part:

Code:
missionData[totalMissions].Name = [[NSMutableString alloc] init];
missionData[totalMissions].Name = [currentNodeContent mutableCopy];
In the first line, you're creating a new, blank mutable string and assining its address to the Name pointer, and in the second line, you're creating another mutable string that's a copy of currentNodeContent and assigning the address of THAT object to the same pointer. The first NSMutableString then gets lost in memory.

So get rid of that first line and you should be fine.
SoulRed12 is offline   Reply With Quote
Old 09-12-2010, 12:57 AM   #3 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 31
EthanK is on a distinguished road
Default

Thanks a ton SoulRed, that fixed it. That makes a lot of sense looking at it now, not sure why I was thinking I needed to get a new memory alloc before I could copy. :-)

Sorry for the late reply, I was on a sabbatical since the op, really appreciate the help!
EthanK is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 347
5 members and 342 guests
freewind, givensur, lendo, Newbie123, PlutoPrime
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,894
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 12:53 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0