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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:27:47+00:00 2026-05-23T15:27:47+00:00

if object has property of type NSString or NSNumber , which is better, retain

  • 0

if object has property of type NSString or NSNumber, which is better, retain or copy?

I think these objects are immutable, (can not change state of object) so copy is better?

I see the example why copy is better that assign NSMutableString and change it, but there’s no NSMutableNumber. Then in the case of NSNumber, I’d better use retain to NSNumber objects?

If copy is better because NSString and NSNumber has small memory usage, how about if property is NSArray type?

NSArray type is also immutable, what about use copy in NSArray properties?

  • 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-23T15:27:47+00:00Added an answer on May 23, 2026 at 3:27 pm

    With immutable objects, copy.

    For immutable objects like most NSStrings, -copyWithZone: is effectively

    -(id) copyWithZone: (NSZone*) zone
    {
        return [self retain];
    }
    

    so the overhead is minimal.

    With mutable objects, probably copy but with large mutable objects like strings and large mutable arrays, you need to make a judgement call based on profiling your code. Also, of course, with mutable objects you might want the original because you might want to see the changes in the original.

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

Sidebar

Related Questions

I have object A which in turn has a property of type Object B
I have an object which has a property of type ObservableCollection<bool> . It is
I have objects that has a DateTime property, how can i query for the
For my objects, I am using Csla, which has a BrokenRulesCollection property. I would
I have a producer/consumer process. The consumed object has an ID property (of type
I've got an object that has a type property. When the type is set
I have an object that has a KeyValuePair type property. I would like to
I have an object that has just one member with a property of type
I have an NSArray of objects , which has a particular property called name
I have a list of objects. Each object has a property named ext that

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.