Re: Simple memory problem
Re: Simple memory problem
- Subject: Re: Simple memory problem
- From: Martin Wierschin <email@hidden>
- Date: Thu, 5 Feb 2009 22:32:05 -0800
On Feb 5, 2009, at 4:42 PM, Steve Sisak wrote:
NSString * newString = [inputString
stringByReplacingCharactersInRange:range withString:@""];
[inputString release]; // release old inputString
inputString = [newString retain]; // retain new inputString
This sequence is not safe. As an optimization there is nothing
preventing "inputString" from returning self if "range" is of zero
length. If that ever happened, you could end up deallocating the
string before the following retain occurs. As has been suggested,
using a single mutable string is probably the best way to go.
~Martin
_______________________________________________
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