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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:17:27+00:00 2026-05-13T16:17:27+00:00

Given the next code snippet: … – (void) setTotalAmount: (NSNumber*)input { [totalAmount autorelease]; totalAmount

  • 0

Given the next code snippet:

…

- (void) setTotalAmount: (NSNumber*)input
{
    [totalAmount autorelease];
    totalAmount = [input retain];
}

- (void) dealloc
{
    [totalAmount release];
    [super dealloc];
}

…

What I want to understand how really we set value.
We allocate local (instance) var and “retain” to input var. But what is “input”? Is it a pointer to real value? Or is it value itself?
When we “retain” do we get a pointer to “input” or pointer to value or just the value?

And pretty same questions with dealloc and release. What actually “dies” here?

Thank you!

  • 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-13T16:17:27+00:00Added an answer on May 13, 2026 at 4:17 pm

    It’s clear that input is a pointer. You have declared its type in the argument list as NSNumber*.

    input is a pointer to an object of type NSNumber. Internally, the object has an integer variable that holds the number of external references to it. Sending the retain message to an object will increment its reference count. Sending the release message will decrement the count. Sending the autorelease message will adds the object to the local autorelease pool which will keep track of autoreleased objects and sends the release message to them next time it drains. An object with reference count of 1 that receives a release message will get deallocated and its dealloc method will get called. You should release all the resources you hold when you are deallocated.

    When you are setting a property, you want to release the old value and make sure the new value is kept around as long as the object itself is alive. To make sure the new value is kept around, you increment its reference count by 1 by sending it the retain message. To release the old object, you’ll send it the release message. There’s one subtle issue here. If the old value is the same as the new value, if you release the old value first and its retain count was 1, it’ll get destroyed before you can increment it. That’s why you should retain the new value before releasing the old one.

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

Sidebar

Ask A Question

Stats

  • Questions 509k
  • Answers 509k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer m_OverLaped.hEvent = CreateEvent(NULL,TRUE,FALSE,NULL); ... ConnectNamedPipe(hPipe, &m_OverLaped); Since the pipe is… May 16, 2026 at 4:33 pm
  • Editorial Team
    Editorial Team added an answer If you have perl installed: perl -ne 'print join "… May 16, 2026 at 4:33 pm
  • Editorial Team
    Editorial Team added an answer The window.location is an object with useful properties for this,… May 16, 2026 at 4:33 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a code snippet in C# but unable to convert to VB.NET. I
I don't have much experience doing unit testing. From what I learned, code should
While writing some C code, I decided to compile it to assembly and read
Full disclosure, this is part of a homework assignment (though a small snippet, the
Given multiple websites all running the same sourcecode, what's the best/most maintainable way to
Given the following template: template <typename T> class wrapper : public T {}; What
Given a set of two or more logical conditions, is it possible to algorithmically
This bug has given me hours of anguish. This is a simplified version of
In my iphone application i am using MKMapView to display any region(i.e Australia) and
Not sure how to word this algorithm question, actually. I have toggle buttons in

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.