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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:02:34+00:00 2026-05-29T11:02:34+00:00

Okay say I have a function like below: -(NSNumber *)calculate{ NSNumber *myNum = [[[NSNumber

  • 0

Okay say I have a function like below:

-(NSNumber *)calculate{
  NSNumber *myNum = [[[NSNumber alloc]initWithInt:5] autorelease];
  return myNum;
}

When will myNum be released? Will whenever I call calculate, myNum will be created and added to the stack?

Also say I have a property like:

@property (nonatomic, retain) NSMutableArray *inputsArr; 

and I synthesized it as:

@synthesize inputsArr = _inputsArr;

and I alloc and initiate it in the code of one of mu functions..
How would I go about releasing this memory? any guides to CoaCoa memory management…I can only find really confusing or obvious guides..
Thanks in advance

  • 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-29T11:02:35+00:00Added an answer on May 29, 2026 at 11:02 am

    autorelease pools are thread local stacks — you push and pop them. the deferred release message will be sent to the object when the pool is destroyed.

    consider this:

    NSAutoreleasePool * pool = [NSAutoreleasePool new];
    NSNumber * n = [NSNumber numberWithDouble:1.0/17.0]; << n is autoreleased
    [n self]; << OK!
    [pool release]; << n is messaged release
    [n self]; << BAM!
    

    So ‘when’ really depends on how the autorelease pools are built — but it’s always possible to ensure your objects outlive a local pool, so this is never a restriction:

    NSAutoreleasePool * pool = [NSAutoreleasePool new];
    NSNumber * n = [NSNumber numberWithDouble:1.0/17.0]; << n is autoreleased
    [n self]; << OK!
    [n retain];
    [pool release]; << n is messaged release
    [n self]; << OK!
    [n release];
    [n self]; << BAM!
    

    The above is what you should rely on. In some real world cases, an object may still be alive where you would expect “BAM!”, but you should never rely on “well, it should have been destroyed, but it seems to work alright”.

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

Sidebar

Related Questions

Okay, let's say we have a class defined like public class TestClass { private
Okay, so say I have a class that looks like this : public class
Okay, lets say I have a URL like so, which is mapped via HTTP
How can I re-use a function? Okay lets say I have this main function
Okay so say I have a form element like this: HTML: <div class=form-item> <label>Current
Okay so my question is this. Say I have a simple C++ code: #include
Okay, so let's say I have a class file called Orange, and then two
Okay say I have two timestamps saved in database in the format yyyymmdd, a
Okay lets say I have a list, and I want to check if that
Okay. Say I have string '193' And I want to remove the last numbers

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.