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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:59:15+00:00 2026-05-25T19:59:15+00:00

So, this is pretty standard memory management, from what I understand: ClassName *temp=[[ClassName alloc]

  • 0

So, this is pretty standard memory management, from what I understand:

 ClassName *temp=[[ClassName alloc] init];
 self.ivar=temp;
 [temp release];

This is to avoid the memory leak created by just doing this:

 self.ivar=[[ClassName alloc] init];

Cool. But, suppose I have several ivars that are based ClassName? Is this okay:

 ClassName *temp=[[ClassName alloc] init];
 self.ivar=temp;
 self.othervar=temp;
 self.anothervar=temp;
 [temp release];

Would they all be manipulating the same object, ultimately, even though I want them to have different instances of ClassName? I assume that the outcome of this might depend on if the ivars were created as retain vs copy? Suppose they are set to retain, would this be okay?

  • 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-25T19:59:15+00:00Added an answer on May 25, 2026 at 7:59 pm

    Would they all be manipulating the same object, ultimately, even though I want them to have different instances of ClassName?

    the default expectation is “yes, they would reference the same object because this is a reference counted system.”

    I assume that the outcome of this might depend on if the ivars were created as retain vs copy?

    not might, but entirely. if the property is declared copy and the type adopts NSCopying, that should be all that is needed. if you implement the setters (what are often synthesized properties) yourself, you must copy in your implementations.

    Suppose they are set to retain, would this be okay?

    then they would all refer to the same instance. whether that is the correct semantic for your program depends on how you need it to behave. in this example, you stated “I want them to have different instances of ClassName” so you would either need to create an unique instance for every destination (either directly or via copy, if ClassName adopts NSCopying).

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

Sidebar

Related Questions

This is pretty simple, I come from a swing/awt background. I'm just wondering what
So I'm using this pretty standard jquery plugin pattern whereby you can grab an
I'm pretty new to C, so I apologize if this is pretty standard knowledge..
I'm new to JPA, so forgive this question if this is pretty standard functionality,
Does anyone know what causes the following errors? This seems like a pretty standard
I am sure this is pretty standard stuff, but I can't seem to wrap
This pretty much has me defeated. On XP and earlier versions of Windows you
this pretty much is the thing. When in tinymce I press anything that is
I find this pretty confusing. When you want to rotate a view, it's going
I'm stuck with this pretty silly thing; I got a textfile like this; Hello::140.0::Bye

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.