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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:58:28+00:00 2026-05-20T18:58:28+00:00

I have a beginner’s question about releasing variables and not wasting memory… I don’t

  • 0

I have a beginner’s question about releasing variables and not wasting memory…

I don’t quite understand when to release variables. I understand that I should always do this if I have assigned them in my header file (in my @interface section and my @property commands). I release them in my -(void)dealloc function.

However, what am I supposed to do with variables that I happen to use in some of my methods, e.g.:

for (int temp = 0; temp < 3; temp++) {
    // do something...
}

[temp release];

This is obviously wrong (at least xCode tells me so), as ‘temp’ is undeclared. But why? I’ve declared it as an int and temp thus takes up space in my memory, I’m sure. How do I tell the program to free up the space temp has taken after I don’t need it anymore? I’m sure this is obvious, but I simply don’t get it.

I’d be very happy for any suggestions for a beginner of how not to be a memory pig and to have ‘memory leaking’ everywhere in my apps…

  • 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-20T18:58:29+00:00Added an answer on May 20, 2026 at 6:58 pm

    You declared it as an int in the scope of the loop. Once the loop is done, it goes out of scope.

    Also, you can not release an int, which is a primitive type. You can only release a subclass of NSObject. A good rule of thumb is that you eventually have to release anything that you called alloc or retain on.

    Edit: For your edification, memory management only applies to objects allocated from the heap. That would be NSObjects obtained via “alloc” or must C-level memory allocated with something like “malloc()”. Declaring a variable like “int x” is called an “auto” variable in that is is created on the stack and will AUTOmatically disappear then that block ends (the end of a “block” being the end of the function or perhaps the end of a {} pair or even the end of a for/if/while block.

    Since Objective-C is basically just a special version of C (with messages), it does not create permanent objects unless you explicitly tell it to. This is different form languages like Python or Javascript.

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

Sidebar

Related Questions

I am a beginner of python and have a question, very confusing for me.
I have written a program with both a Advanced Mode and a Beginner Mode
I'm an absolute beginner, you see. Say I have a string object on the
Q: I'm a beginner to the XML.I have some data comes from my database,
I have been programming for about 3 years now and feel confident in my
As an Objective-C beginner, I'm very confused about the init function, and how and
I'm sorry if this question frustrates anyone ... I am truly a beginner to
Have just started using Google Chrome , and noticed in parts of our site,
Have you ever seen any of there error messages? -- SQL Server 2000 Could
Have you guys had any experiences (positive or negative) by placing your source code/solution

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.