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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:23:42+00:00 2026-05-14T02:23:42+00:00

in the following piece of code I got from a book. The NSString *pPath

  • 0

in the following piece of code I got from a book.

The NSString *pPath which is defined in the class as an instance variable.

@interface MainViewController : UIViewController {
    NSString *pPath;
}

In the implementation after being set it is being retained. I assume that with the assignment the object is automatically retained (because it is an NSString) and there is no need to additionally retain it.

- (void) initPrefsFilePath { 
     NSString *documentsDirectory = 
     [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]; 

     pPath = [documentsDirectory stringByAppendingPathComponent: 
           @"flippingprefs.plist"]; 

     [pPath 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-14T02:23:42+00:00Added an answer on May 14, 2026 at 2:23 am

    Yes, you need to retain your pPath variable if you obtain it this way. However it is not the end of the story – you also need to release its previous value otherwise it will just leak.

    To make things easier you can use objective-c properties that allow you to automatically generate setter/getter methods with desired memory management behavior:

    // header
    @interface MainViewController : UIViewController {
        NSString *pPath;
    }
    @property (nonatomic, retain) NSString* pPath;
    
    // implementation
    
    @synthesize pPath;
    
    - (void) initPrefsFilePath { 
         NSString *documentsDirectory = 
         [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]; 
    
         self.pPath = [documentsDirectory stringByAppendingPathComponent: 
               @"flippingprefs.plist"]; 
    } 
    

    Here in self.pPath=... line automatically generated setter method will get called which:

    1. Will release previously set pPath value
    2. Will assign new value to pPath and retain it

    You will also need to release your pPath variable in dealloc method:

    -(void) dealloc{
      [pPath release];
      //or
      self.pPath = nil;
      [super dealloc];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got the following piece of SQL Code that is giving me a titular
I've got the following piece of Jquery: $(#collapse-menu > li > a).click(function() { $(this).toggleClass(expanded).toggleClass(collapsed).find(+
I've never used Java AWT before and now I've got a piece of code
I am trying to declare and use a class B inside of a class
I was trying to parse mathml document using JScience but was not succeed. Following
I've got an sqlite db with long and lat of shops and I want
I got a question regarding content types and their IDs and how to use
I already posted a question regarding it, but at that time I haven't have
I haven't solved this issue by using the stored procedure, yet we've decided to

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.