Re: stringByReplacingCharactersInRange leading to bus error
Re: stringByReplacingCharactersInRange leading to bus error
- Subject: Re: stringByReplacingCharactersInRange leading to bus error
- From: Dave Carrigan <email@hidden>
- Date: Tue, 17 Aug 2010 21:48:48 -0700
On Aug 17, 2010, at 2:03 PM, James Miller <email@hidden> wrote:
> Hello.
>
> I'm a little new to Objective-C / Cocoa so please don't shoot me, but I've been looking around for a few hours and can't seem to figure out what I'm doing wrong on my own and could use a second/third/fourth set of eyes.
>
> I have NSTimer that runs several times a second against an NSString called level, which is 190 characters long and previously initialized from:
>
> // NSString *level = [[NSString alloc]
> // initWithContentsOfFile:path
> // encoding:NSUTF8StringEncoding
> // error:&error];
>
>
> During the timer call, the level NSString is modified by the following line of code:
>
> level=[level stringByReplacingCharactersInRange:NSMakeRange(5,1) withString:@" "];
You don't own the resulting string and it's probably getting autoreleased by the next time you're in the timer. You'll need to retain the result of stringByReplacingCharactersInRange.
>
Dave Carrigan
Seattle, WA_______________________________________________
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