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 1023699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:39:58+00:00 2026-05-16T11:39:58+00:00

I have a NSString declared in the interface part: @property (nonatomic, retain) NSString *filePath;

  • 0

I have a NSString declared in the interface part:

@property (nonatomic, retain) NSString *filePath;

In viewDidLoad I give this a value and when I am trying to call it from one of my custom methods it works for the first time but on the second it crushes. In my opinion filePath was autoreleased during the first call.

I tried a different approach, in my method I have done something like this:

NSString *path = [[[NSString init] alloc] autorelease];
path = [filePath copy];

and this time seems to work, but when checking the retainCount of path it is constantly increasing.
The first time the method is called, retainCount is 4 but for the second is 2, third is 3 and so on.

Ok, I understand for filePath to be increasing, because of [copy] but why also for path variable?
And why in the first case it didn’t worked?

  • 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-16T11:39:59+00:00Added an answer on May 16, 2026 at 11:39 am

    You don’t show all code so it is hard to say anything conclusive. However:

    NSString *path = [[[NSString init] alloc] autorelease];
    path = [filePath copy];
    

    makes no sense: first you allocate an NSString, and let path point to it. Then you let path point to something else. The NSString is not used (but will be cleaned up by the autorelease).

    I see you access filePath just by its name, not through the getter/setter. If you use self.filePath, like

    self.filePath = [NSString stringWithFormat:@"..."]; // or any other string
    

    then the retain/release business is handled properly by the setter. To be precise, the difference between filePath = ... and self.filePath = ... is that the latter will retain the object you are assigning.

    You should really not be looking at the retainCount to debug things, if you are not very confident you know what’s happening under the cocoa hood.

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

Sidebar

Related Questions

I have class named Building : @interface Building : NSObject @property (nonatomic,retain)NSString* node; @property
I have an NSString declared like this : .h: @interface ViewController : UIViewController {
I have an NSString declared as @property (nonatomic,copy) NSString *text in a class. When
Suppose I have this code... foo.h @interface Foo : NSObject { NSString *aString; //
I have declared this ivar in my ViewController.h #import <UIKit/UIKit.h> @interface FirstViewController : UIViewController
I have: NSString *promise = @thereAreOtherWorldsThanThese; which I'm trying to transform into the string:
I have this: NSString *string1 = ...; NSString *string2 = ...; NSMutableArray *array =
I have a NSString member variable declared in the header file of the view
I have a method SetBallVisibility declared in the interface for my view controller. However,
I have a property that changes to invalid as I move between viewDidLoad and

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.