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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:49:21+00:00 2026-05-15T21:49:21+00:00

I’m relatively new to Objective C and while I’ve been trucking right along writing

  • 0

I’m relatively new to Objective C and while I’ve been trucking right along writing iPhone apps, I think I need some help understanding something.

I’m storing a dynamic list of strings in an NSMutableArray, which is a property of my main class. In my initialization I alloc and init to store 100 items:

stringList = [[NSMutableArray alloc] initWithCapacity:100];

As strings are acquired (from incoming data) I add them as objects to the array:

NSString *newString = [stringMaker makeStringFromData:data];
[stringList addObject:newString];

So to understand what’s really happening here. If I’ve done this adding 5 times, what do I really have in the NSMutableArray? Just pointers to the 5 strings or the actual strings? I had assumed that addObject actually copied the data. If my stringMaker class were to start properly releasing things could I end up with pointers to nothing? Is there a better way to make sure that the strings in my list are safe from being released or repointed to something else? Or am I misunderstanding how this works?

I’m not currently having a problem with this part so far. But I’m a little shaky on leaks and releasing things.

What lead me to this is that I do have a problem where when I modify one of the strings by:

[stringList replaceObjectAtIndex: stringIndex withObject: stringMaker.lastStringUsed];

that after a while when I come back to access the object at that index, it’s whatever lastStringUsed was last, not what it was when I replaced it. This indicates to me that all I did was set a pointer and didn’t save the data at that pointer. Note that lastStringUsed is a property of the stringMaker class and is an NSMutableString.

So to be clear.. in stringMaker at various points I’m doing a:

 [lastStringUsed setString: someString];

(by the way does THAT actually move the data?)

Then in back in my main class I’m doing that replaceObjectAtIndex shown above. Then some other stringMaker method is resetting lastStringUsed. Then later when I access my stringList at that index it’s the new lastStringUsed value and not whatever it was when I did the replaceObjectAtIndex.

EDIT – SOLVED FOR NOW – STILL NEED TO TAKE A NIGHT CLASS ON NSARRAYS AND STRINGS AND PROPERLY RETAINING AND RELEASING

What I did to fix it for now was to just allocate a new string…

NSString *replacementString = [[NSString alloc] initWithCapacity: 310];
[replacementString setString:stringMaker.lastStringUsed];
[stringList replaceObjectAtIndex:stringIndex withObject:replacementString];

Now the next time I change lastStringUsed it doesn’t also change the one in the stringList.

  • 1 1 Answer
  • 1 View
  • 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-15T21:49:21+00:00Added an answer on May 15, 2026 at 9:49 pm

    When you add an object to an array or dictionary the object will be retained by that array or dictionary. Look at the retain count of the object you are placing into the array before and after you call addObject:

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT

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.