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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:17:36+00:00 2026-05-24T05:17:36+00:00

I have a NSMutableArray in my app which I initiate like this: H-FILE NSMutableArray

  • 0

I have a NSMutableArray in my app which I initiate like this:

H-FILE

NSMutableArray *noteBookContent;
@property (nonatomic, retain) NSMutableArray *noteBookContent;

M-FILE

@synthesize noteBookContent;

I then have a method in which I open a txt file and read its contents into a temp NSString and slices this NSString into different bits which are then put into the NSMutableArray. Like so:

    NSString *tempTextOut = [NSString stringWithContentsOfFile:filePath
                                                          encoding:NSUTF8StringEncoding
                                                             error:&error];

self.noteBookContent = [[[tempTextOut componentsSeparatedByString: @"\n[DIVIDER]\n"] mutableCopy] autorelease];

My big question is what happens if I repeat the same process a couple of times. Is there a need to release the noteBookContent before I read new data into it? Is there a chance of data being messed up, e.g. if one noteBookContent has 10 items (all called FRUIT) and the next noteBookContent has 5 items (all called SALAD), may I end up with SALAD, SALAD, SALAD, SALAD, SALAD, FRUIT, FRUIT, FRUIT, FRUIT etc.?

Sorry if this is obvious, but I don’t really understand what happens in the moment that I read new data into an NSMutableArray which already contains old data.

Thanks for any explanations!

  • 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-24T05:17:37+00:00Added an answer on May 24, 2026 at 5:17 am

    In this case you’re not actually changing the contents of the array—you’re replacing the object entirely. The old value of noteBookContent—the NSMutableArray instance—gets released by the property assignment (the .noteBookContent = ...), and replaced with a new, separate NSMutableArray that’s created by the -mutableCopy call. A more efficient way to do it would be this:

    [self.noteBookContent removeAllObjects];
    [self.noteBookContent addObjectsFromArray:[tempTextOut componentsSeparatedByString: @"\n[DIVIDER]\n"]];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an app which saves its user data into a file in the
I have this code: tableList = [[NSMutableArray alloc] initWithObjects:@First View,@Second View,nil]; I have synthesized
So I have a UITableView which should loop through a single NSMutableArray and use
Scenario I have made a phonegap 1.0.0 app which loads the current location via
I have a method which returns an NSArray with points to be plotted. Following
I have an iPhone app which sends a request to a url posting a
I have this: NSMutableArray *myMArray and I have 2 IBaction , (insert) & (remove)
My Case: I have original Page Control app from Apple. I would like to
I have an app which goes through a set of screens within a navigation
I have been working on an app all day which has been working fine

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.