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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:22:18+00:00 2026-06-01T04:22:18+00:00

I noticed that my program was crashing because it was running out of memory.

  • 0

I noticed that my program was crashing because it was running out of memory. I figured out that this was happening because of this code segment:

DataSet *tempSet = [[DataSet alloc] init];          
tempSet.rightFoot = [NSNumber numberWithDouble:temp1];
tempSet.leftFoot = [NSNumber numberWithDouble:temp2];
[footData addObject:tempSet];   //add dataSet object to the array
[tempSet release];

I read some tutorials about memory management online and was able to figure out that I needed to do this: (notice the added “autoreleases”)

DataSet *tempSet = [[DataSet alloc] init];          
tempSet.rightFoot = [[NSNumber numberWithDouble:temp1] autorelease];
tempSet.leftFoot = [[NSNumber numberWithDouble:temp2] autorelease];
[footData addObject:tempSet];   //add dataSet object to the array
[tempSet release];

I am still confused about why I had to do this. I did not use alloc, new or copy when creating the numberWithDouble.

Does this mean that I would need to add autorelease in this situation as well?:

[subset addObject:[NSNumber numberWithDouble:temp]];

What about this situation?:

tempSet.rightFoot = [NSString stringWithString:@"temp"];

I appreciate any help.

  • 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-01T04:22:20+00:00Added an answer on June 1, 2026 at 4:22 am
    +numberWithDouble
    

    is called a convenience method. Meaning, it replaces the little section of code that would look like this:

    [[[NSNumber alloc]initWithDouble:double]autorelease];
    

    Most (if not all) convenience methods are auto release by default, so the OP code with the autoreleases is incorrect, as it drops the retain count to -1.

    The equals sign however is equivalent to

    [self setRightFoot:[[[NSString alloc]initWithString]autorelease]];
    

    which increments rightFoot’s retain count and requires it to be released elsewhere.

    as for the -addObject code, it returns void, so it does not in fact increment the receiver’s retain count, and requires no release of the receiver. The object in the array should already be released by the convenience method for later, which doesn’t matter because the array is now holding “copy” of it.

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

Sidebar

Related Questions

I noticed that I can start a program with it's associated handler by writing
I noticed that in Windows 7 there is a Program called Windows Fax and
I'm working on a database program and I noticed that when I'm doing queries
I noticed while making a program that a lot of my int type variables
I'm trying to write a program that cleans data, using Matlab. This program takes
I have a running dispute with a colleague. He's written a program that I'm
I have a program that relates to a database. I start out my program
I noticed that If I run strings on my program which was compiled by
I noticed that in Windows 7, unlike XP, if a program crashes that I
I've noticed that when I start up a program that sets up a couple

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.