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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:41:07+00:00 2026-05-23T02:41:07+00:00

I just started programming in Objective-C. Prior to this I was primarily a C#

  • 0

I just started programming in Objective-C. Prior to this I was primarily a C# person.

Please let me know where if I release the memory in the following code in a correct manner.

     @implementation CalculatorViewController

    -(CalculatorBrain *) brain
    {
      if(!brain)
      {
          brain = [[CalculatorBrain alloc] init]; 
      }

        return brain;
    }


 -(IBAction) operationPressed: (UIButton *) sender
{

    NSString *operation = sender.titleLabel.text;

    if(userInMiddleOfTypingDigit)
    {

        [self brain].operand = display.text.doubleValue;
        userInMiddleOfTypingDigit = NO;
    }

    double result = [[self brain] performOpeaation:operation];

    [display setText:[NSString stringWithFormat:@"%g",result]];
}


- (void)dealloc 
{   
    [brain release];

    [super dealloc];
}

Basically I am doing lazy initialization as shown in Stanford university tutorial. But not sure if I am releasing memory correctly.

Please correct me if there is something wrong.

Thanks,

  • 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-23T02:41:07+00:00Added an answer on May 23, 2026 at 2:41 am

    Yes, that looks fine. For that matter, instead of this:

    [self brain].operand = display.text.doubleValue;
    

    you could also do this:

    self.brain.operand = display.text.doubleValue;
    

    They’re exactly equivalent. Some people like the dot syntax, some don’t. But where you were already using it in one place, you may as well be consistent.

    Note that if you plan on this class being accessed by multiple threads, then you would want to protect the lazy initialization check from synchronization issues. But that’s outside the scope of this question, I think. Your memory management is fine.

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

Sidebar

Related Questions

sorry for this newb question, i just started programming with php I'm following Yahoo
I have just started programming in Objective-C, I understand it only partially supports method
I have started learning Objective C with no prior programming experience from the 'Become
I've just started programming in PyQt and I'm following Rapid GUI programming in Python
I'm just getting started in web programming and so I'm sure this is a
I just started thinking about creating/customizing a web crawler today, and know very little
I've just started learning D Programming. I'd like to deploy my programs on an
I've started programming on Mac OS X in Objective-C and decided to create a
I'm a Java guy who is familiar with Swing programming and recently just started
Just started programming in C++. I've created a Point class, a std::list and an

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.