• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: stringByReplacingCharactersInRange leading to bus error
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: stringByReplacingCharactersInRange leading to bus error


  • Subject: Re: stringByReplacingCharactersInRange leading to bus error
  • From: "John C. Randolph" <email@hidden>
  • Date: Wed, 18 Aug 2010 11:06:40 -0700

-stringByReplacingCharactersInString: creates and returns a new string, which is autoreleased.  You're getting the bus errors when something tries to access that string after it's been released.

-jcr


On Aug 17, 2010, at 2:03 PM, James Miller 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:@" "];
>
> This operation appears to succeed as I print it via NSLog and it looks fine and the length checks out, but the next time through the NSTimer I get a bus error and the application dies.
>
> If I comment out the line above, the code continues to run fine. Am I doing something wrong in terms of how I am using this method or assigning it back to the NSString?
>
>
> I appreciate the help!
>
> --Jim_______________________________________________
>
> 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

_______________________________________________

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

  • Follow-Ups:
    • Re: stringByReplacingCharactersInRange leading to bus error
      • From: Murat Konar <email@hidden>
References: 
 >stringByReplacingCharactersInRange leading to bus error (From: James Miller <email@hidden>)

  • Prev by Date: key pair generation problem
  • Next by Date: Re: stringByReplacingCharactersInRange leading to bus error
  • Previous by thread: Re: stringByReplacingCharactersInRange leading to bus error
  • Next by thread: Re: stringByReplacingCharactersInRange leading to bus error
  • Index(es):
    • Date
    • Thread