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

  • SEARCH
  • Home
  • 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 834083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:37:17+00:00 2026-05-15T04:37:17+00:00

In my Cocoa application, in the header file, I declare a NSString ivar: NSString

  • 0

In my Cocoa application, in the header file, I declare a NSString ivar:

NSString *gSdkPath;

Then, in awakeFromNib, I assign it to a value:

gSdkPath = @"hello";

Later, it’s value is changed in the code:

gSdkPath = [NSString stringWithString:[folderNames objectAtIndex:0]];

(the object returned from objectAtIndex is an NSString)

However, after this point, in another method when I try to NSLog() (or do anything with) the gSdkPath variable, the app crashes. I’m sure this has something to do with memory management, but I’m beginning with Cocoa and not sure exactly how this all works.

Thanks for any help in advance.

EDIT: This was solved by retaining the string [gSdkPath retain].

  • 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-05-15T04:37:18+00:00Added an answer on May 15, 2026 at 4:37 am

    (the object returned from
    objectAtIndex is an NSString)

    Are you sure? I suggest putting this in it’s own temporary variable and double checking that it’s not nil or invalid in some way.

    Edit: If that is OK so far, do note that stringWithString returns an autoreleased object. You need to retain it if you want to use it “later”.

    gSdkPath = [NSString stringWithString:[folderNames objectAtIndex:0]];
    [gSdkPath retain];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given a Cocoa application which runs on Mac OS X 10.7 and later: What
I did a cocoa application in which the file dialog box is opening when
I'm writing a Cocoa application that displays the contents of an archive file in
Scenary A Cocoa application with a WebView element that loads file:///index.html A local resource
I'm developing a Cocoa application, and I'm using constant NSString s as ways to
I have a Cocoa application which reads and saves data in a sole file.
My Cocoa application somehow does not reopen non-minimized after having been minimized and then
My Cocoa application displays file icons for all files in a given folder. I'm
I'm building an Cocoa application that modifies a file on the user's operating system
In a Document-based Cocoa application, handled file extensions are listed in the application's Info.plist

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.