• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
XML Resource Release
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

XML Resource Release


  • Subject: XML Resource Release
  • From: Bing Li <email@hidden>
  • Date: Thu, 19 May 2011 01:55:24 +0800

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 (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

  • Follow-Ups:
    • Re: XML Resource Release
      • From: "Hank Heijink (Mailinglists)" <email@hidden>
    • Re: XML Resource Release
      • From: Fritz Anderson <email@hidden>
    • Re: XML Resource Release
      • From: Conrad Shultz <email@hidden>
    • Re: XML Resource Release
      • From: Ken Thomases <email@hidden>
  • Prev by Date: Re: NSSlider's mouseDown,mouseUp,mouseDrag - process separately
  • Next by Date: Re: XML Resource Release
  • Previous by thread: Re: Unrecognized document type (Solved?)
  • Next by thread: Re: XML Resource Release
  • Index(es):
    • Date
    • Thread