On Sat, Jun 11, 2011 at 1:03 PM, Bing Li <lbl...@gmail.com> 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 (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