Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8944003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:55:33+00:00 2026-06-15T11:55:33+00:00

i get EXC_BAD_ACCESS while formatting string. NSString *object = [[NSUserDefaults standardUserDefaults] stringForKey:@ObjectNumber]; NSString *pin

  • 0

i get EXC_BAD_ACCESS while formatting string.

NSString *object = [[NSUserDefaults standardUserDefaults] stringForKey:@"ObjectNumber"];
NSString *pin = [[NSUserDefaults standardUserDefaults] stringForKey:[NSString stringWithFormat:@"Pin%i ",object.intValue]];
NSString *msg = [NSString stringWithFormat:@"%@N", pin];

NSString *msg2 = @"0001N";

NSLog(@"Sending %@", msg);

tcpConnection *Obj = [tcpConnection alloc];
[Obj loadUpConnection:msg];

If i use msg2 everything works fine. But if i use msg it gets exc_bad_access even though NSLog prints msg correctly.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T11:55:35+00:00Added an answer on June 15, 2026 at 11:55 am

    I suspect that your loadUpConnection: method isn’t retaining its parameters.

    It seems that there’s a lot for you to learn in regards to objective-c.

    I worry that this will confuse you more than help, but the msg2 variable is pointing to a static instance of the string "0001N" (because you hardcoded it at compile time the system creates a static instance to use). This is why it doesn’t crash when you use msg2, but does when you use msg. msg is pointing to a dynamically allocated instance. The reference returned to you is ‘autoreleased’ which means it will be released at some point in the future (usually at the end of the run loop iteration). If your loadUpConnection: method doesn’t retain it’s parameters, then the msg string will be released before you try to use it, causing the EXC_BAD_ACCESS error. Because msg2 is a static instance, it will never be deallocated, hence it not crashing.

    My only advice would be to continue learning – pick up a book, I recommend ‘Programming in Objecive-C’ by Stephen Kochan, or ‘iPhone Programming A Big Nerd Ranch Guide’ by Aaron Hillegass.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I get a EXC_BAD_ACCESS while running a NSOpenPanel to select a directory on the
While developing for iphone i get EXC_BAD_ACCESS when doing sqlite3 *memory_db; if (sqlite3_open(:memory:, &memory_db)
I seem to get an EXC_BAD_ACCESS error when I select a cell in my
Many a times I get the error EXC_BAD_ACCESS and my application terminates and I
I'm trying to set up an SKProductsRequest, but I continually get the error EXC_BAD_ACCESS.
I've been using http://code.google.com/p/plblocks/ for a while now to get blocks support in our
I have an app of sending free text MSG .. While i select a
I have a weird issue that comes up while releasing an object. In the
Possible Duplicate: Why do I get a segmentation fault when writing to a string?
I am making a command-line tool using Xcode 4. I get the EXC_BAD_ACCESS error

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.