Release variable and assigning it again

Posted by David Gonrab on Stack Overflow See other posts from Stack Overflow or by David Gonrab
Published on 2010-06-17T07:25:59Z Indexed on 2010/06/17 7:33 UTC
Read the original article Hit count: 154

Filed under:
|

What is the preferred and/or correct way to release an NSMutableString (or any other class for that matter) instance and assign a new instance to the same variable in Objective-C on the iPhone?

Currently I'm using

[current release];
current = [NSMutableString new];

but I understand that the following works, too.

NSMutableString *new = [NSMutableString new];
[current release];
current = [new retain];
[new release];

The variable current is declared in the interface definition of my class and gets released in dealloc.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c