Dear all,

I am creating an XML chars to transmit over TCP. When an XML is created, I
attempt to release some resources. However, I got some weird results.

The XML is simple as follows.

<?xml version="1.0" encoding="UTF-8"?>
 <MessageRoot>
        <PeerKey>2412432</PeerKey>
        <PeerName>greatfree</PeerName>
        <Password>111111</Password>
 </MessageRoot>

The code to create the above XML is as follows. It runs well.

+ (const char *) CreateSignInMessage: (NSString *)peerKey PN: (NSString
*)peerName PW:(NSString *)password
{
        NSXMLElement *root = [NSXMLNode elementWithName:"MessageRoot"];
        NSXMLDocument *xmlDoc = [[NSXMLDocument alloc]
initWithRootElement:root];
        [xmlDoc setVersion:"1.0"];
        [xmlDoc setCharacterEncoding:"utf-8"];

        NSXMLElement *peerKeyElement = [NSXMLNode
elementWithName:"PeerKey"];
        [root addChild:peerKeyElement];
        [peerKeyElement addChild:[NSXMLNode textWithStringValue:peerKey]];

        NSXMLElement *peerNameElement = [NSXMLNode
elementWithName:"PeerName"];
        [root addChild:peerNameElement];
        [peerNameElement addChild:[NSXMLNode textWithStringValue:peerName]];

        NSXMLElement *passwordElement = [NSXMLNode
elementWithName:"Password"];
        [root addChild:passwordElement];
        [passwordElement addChild:[NSXMLNode textWithStringValue:password]];

        NSData *data = [xmlDoc XMLDataWithOptions:NSXMLNodePrettyPrint];
        NSString *xmlStr = [[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding];
        const char *xmlChar = [xmlStr UTF8String];

        [passwordElement release];
//        [peerNameElement release];
//        [peerKeyElement release];
        [root release];
        [xmlDoc release];
        [xmlStr release];
        [data release];

        return xmlChar;
}

But, if the releasing lines are changed as follows, it gets exceptions.

....

        [passwordElement release];
        [peerNameElement releases]; // The line is added.
        [root release];
        [xmlDoc release];
        [xmlStr release];
        [data release];

....

Could you please figure out what is the problem?

Best regards,
Bing
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to