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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:12:06+00:00 2026-05-12T09:12:06+00:00

I am cleaning up my code in a phonebook iPhone application and the Leaks

  • 0

I am cleaning up my code in a phonebook iPhone application and the Leaks tool in Instruments is reporting that I am leaking NSCFString objects. Here is the pattern that I am following:

I have a Person class in my application that has nothing more than local NSString members and associated properties for first name, last name, etc.

My view controller has an NSMutableArray property that is populated from a SQLite database in the searchBarSearchButtonClicked event. This NSMutableArray is populated with Person object(s) that will be used to populate my tableview control. Also, if the user clicks on a person in the view, their Person object will be passed to the Detail view for viewing additional information than just the name.

When I perform my first look up and display the results there are no memory leaks.

Now, when I perform my second look up I would ideally like to clear out the NSMutableArray and reload it with the new result set without leaking memory. So, to do this, I call removeAllObjects on my personList property and then call the database to repopulate the personList NSMutableArray as shown below:

[self.personList removeAllObjects];
self.personList = [SearchService GetPersonList:searchText];
[list reloadData];

By calling removeAllObject I’ve gotten rid of the leaks that I used to have that were associated with the Person objects. However, it appears that I am now leaking the NSString objects left over from the properties of the individual Person objects.

Is this possible?

I am new to the Instruments tool but from what I can tell from the Extended Detail when I drill into one of the NCSFString leaks is that last line of code in the stack is often pointing to the @synthesize line of code for the property, such as:

@synthesize firstName;

So, that is why I think those NSStrings are not getting cleaned up. Is there a better way to do this that doesn’t produce memory leaks?

  • 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-12T09:12:07+00:00Added an answer on May 12, 2026 at 9:12 am

    Do you release the NSStrings in the dealloc method for your Person class?

    Assuming that you set up your property as so:

    @property (retain) NSString *firstName;
    

    When you set firstName using the setter, it will be retained. If the Person instance is then released and deallocated, but firstName has not been released it will leak.

    Put it in the dealloc method in your Person class:

    - (void)dealloc
    {
        [firstName release];
        [super dealloc];
    }
    

    (Assuming the corresponding ivar that is used for your firstName property is called firstName).

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

Sidebar

Related Questions

here a a piece of code that is supposed to loop over and over
So I'm working in Delphi 2007 and I am cleaning up my code. I
I'm working on cleaning up some of my code and I came to a
Today, I was cleaning up some of my code with FXCop and it complained
I am just going to be honest and say that I hate building web
The code below works for Delphi XE, but the 2400 buffersize is pretty ugly.
For a bit fall cleaning, I am moving 25 tables between MySQL databases (different
What would cause code to execute on the simulator, but not execute properly on
I created an error-handler using On Error Goto statement, and I put a few
I'm trying to use flymake on emacs 22.3.1 on openSuse 11 but I got

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.