Re: XML Resource Release
Re: XML Resource Release
- Subject: Re: XML Resource Release
- From: Fritz Anderson <email@hidden>
- Date: Wed, 18 May 2011 13:23:01 -0500
On 18 May 2011, at 12:55 PM, Bing Li wrote:
> NSXMLElement *root = [NSXMLNode elementWithName:"MessageRoot"];
> NSXMLDocument *xmlDoc = [[NSXMLDocument alloc]
> initWithRootElement:root];
> [xmlDoc setVersion:"1.0"];
> [xmlDoc setCharacterEncoding:"utf-8"];
// etc.
You repeatedly pass C ("", array-of-char) strings to Cocoa methods, which with rare exceptions require NSStrings (@""). Change that.
In fact, the code you are showing us should not have compiled, at least not without many, many warnings. If this isn't your actual source code, it makes it harder for us to help, because you aren't showing us the actual cause of your problem.
> [passwordElement release];
// [peerKeyElement release];
> [peerNameElement releases]; // The line is added.
I assume this is release, not releases.
> [root release];
> [xmlDoc release];
> [xmlStr release];
> [data release];
For future questions, you should say what exception you got and what the stack trace was.
Except for xmlStr and xmlDoc (which were created with alloc), none of these releases are correct. You got those objects from convenience methods, and they are already autoreleased. It's mere chance that you didn't see the consequences until you added another release.
Re-read the memory-management rules. They're simple once you know them, but there's a rule against trying to make a full statement of them on this list.
— F
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden