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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:15:36+00:00 2026-06-10T03:15:36+00:00

Does it? I would normally pick this, NSArray * monthsForChosenYear = [self monthsForYear:newChosenYear]; [self

  • 0

Does it?

I would normally pick this,

NSArray * monthsForChosenYear = [self monthsForYear:newChosenYear];
[self setMonths: monthsForChosenYear];

Over this,

[self setMonths: [self monthsForYear:newChosenYear]];

Mostly because it’s easy to understand at a first glance. Where the second approach, not so much.

But what are really the implications of this? monthsForChosenYear, is just a pointer, but it must be stored somehow.

I’m not asking if the impact is so small that I wouldn’t need to worry about it. But I am very curious about this.

Even a redirect to some document explaining in better detail would be nice.

Thank you in advance!

Nuno

  • 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-06-10T03:15:38+00:00Added an answer on June 10, 2026 at 3:15 am

    A long answer to hopefully assuage your curiosity, and having curiosity is good! The performance & memory impact is either zero or miniscule. You wonder how the pointer is stored. When you type:

    NSArray * monthsForChosenYear;
    

    You are asking for a box (variable), to be referred to by the name monthsForChosenYear, to be allocated in local storage. This box will be automatically reclaimed when the enclosing method exits, and possibly earlier than that if the compiler figures out it is no longer needed. This box can hold a value of type NSArray *.

    When you type:

    NSArray * monthsForChosenYear = [self monthsForYear:newChosenYear];
    

    You are asking for two things, it is just a shorthand for:

    NSArray * monthsForChosenYear;
    monthsForChosenYear = [self monthsForYear:newChosenYear];
    

    and the second line calls a method and stores the returned value in your box named monthsForChosenYear. Finally when you type:

    [self setMonths: monthsForChosenYear];
    

    the value stored in the your box monthsForChosenYear is passed to a method. If you no longer use the box monthsForChosenYear the compiler may reclaim it, or it may wait till the end of the enclosing method or some other suitable point.

    Compilers analyze the usage of boxes and optimise, sometimes they will not even allocate a box if it is determined one is not needed. The cost of allocating a box is infinitesimal.

    *[Note: there are actually usually two kinds of local boxes. The second, often called a register, has an allocation cost which is usually even smaller than infinitesimal. Which kind of box is used is decided by the compiler.]*

    When you type:

    [self setMonths: [self monthsForYear:newChosenYear]];
    

    You are asking for two methods to be called in one line and the value returned from the inner call ([self monthsForYear:newChosenYear]) has to be passed to the outer call. Where does the compiler store this result? The compiler in effect translates the above into:

    NSArray *compilerTemporaryBox = [self monthsForYear:newChosenYear];
    [self setMonths:compilerTemporaryBox];
    

    and from the above you know how that goes. There is a small advantage to the compiler in that it knows how long compilerTemporaryBox is needed, so it doesn’t need to figure it out, but that will not effect the compiled code.

    So after all that the overall answer is it doesn’t matter how you write it.

    Furthermore the type of memory management you use: MRC, ARC or GC; will not effect the answer – the compiler will end up treating both your variants the same.

    So go for the style you find best for you. HTH.

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

Sidebar

Related Questions

Does anyone see why this jquery click function would not work? It is not
Does any one have any idea why this would be happening? This is some
One would normally have this query in their sphinx.conf file : sql_query = SELECT
It am trying to launch this code that would normally run from a batch
I would normally just do this with a drop down list but the client
Does anyone know how I would go about changing (transforming) an image based on
I would like to know how does the login procedure work in the Internet
Does map() iterate through the list like for would? Is there a value in
I would like to ask what does it mean AttributeError: 'unicode' object has no
Does anyone know of a library that would allow me to manipulate Flex DOM

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.