Der Stephen and Nick,

I solved the problem in this way.

- (void) Send
{
     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
     char *message = [self createSendMessage];
     [self send:message];
     [pool drain];
}

It also works. How do you think about the solution?

Best,
Bing

On Sun, Jun 12, 2011 at 1:45 PM, Stephen J. Butler <[email protected]
> wrote:

> On Sat, Jun 11, 2011 at 1:03 PM, Bing Li <[email protected]> wrote:
> >        NSData *data = [xmlDoc XMLData];
> >        NSString *xmlStr = [[[NSString alloc] initWithData:data
> > encoding:NSUTF8StringEncoding] autorelease];
> >        xmlStr = [xmlStr stringByAppendingString:@"\n"];
> >        const char *xmlChar = [xmlStr UTF8String];
> >
> >        [xmlDoc release];
> >        return xmlChar;
> > }
>
> If you're using your own autorelease pools now, be careful about the
> lifetime of your return value (xmlChar)! It will only live as long as
> xmlStr lives. For example, this would be incorrect:
>
> NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
> const char *str = [self createSendMessage:...];
> [pool release];
> // do something with str
>
> You'll want to strdup() the return value to make sure it lives after
> the pool is released, but then you also need to remember to free()
> your strdup() value.
>
_______________________________________________

Cocoa-dev mailing list ([email protected])

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 [email protected]

Reply via email to