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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:41:25+00:00 2026-05-26T01:41:25+00:00

I am a beginner, building a calculator to get myself familiar with ObjC. So

  • 0

I am a beginner, building a calculator to get myself familiar with ObjC.

So far my code is running ok, except the following code.

This function is linked to 5 buttons.

The problem is when i press any of the buttons the first time, the code runs flawlessly, so does the second time, but falls over the third time. it is always the third time that it fails. On screen on the third press the button itself vanishes and program stalls, and then crashes.

-(void) displayOnScreenValue{
[mainDisplay setText:onScreenTextValue];
}

-(void) pressOperatorButton:(id)sender{

    UIButton *pressedOpp = (UIButton *)sender;

    onScreenValue = [onScreenTextValue doubleValue]; //onScreenValue is Double

if (!opJustSet) {

    switch (opSelected) {
        case 0:  //Equal
            //mainDisplay.text = @"=";
            accuValue = onScreenValue;
            break;
        case 1:  //Plus
            //mainDisplay.text = @"+";
            accuValue = accuValue + onScreenValue;

            break;
        case 2:  //Minus
            //mainDisplay.text = @"-";
            accuValue = accuValue - onScreenValue;
            break;
        case 3: //Multiply
            //mainDisplay.text = @"x";
            accuValue = accuValue * onScreenValue;
            break;
        case 4: //Divide
            //mainDisplay.text = @"d";
            accuValue = accuValue / onScreenValue;
            break;

        default:
            break;
    }
    NSNumber* value = [NSNumber numberWithDouble:accuValue];
    onScreenTextValue =[value stringValue];
    [self displayOnScreenValue];
    opJustSet = YES;
    [value release];

}

signChangeSet = NO;
dotUsed = NO;
decimalValue = 0;
opSelected = pressedOpp.tag;

//[self displayOnScreenValue];
[pressedOpp release];
}
  • 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-26T01:41:25+00:00Added an answer on May 26, 2026 at 1:41 am

    In this code:

    NSNumber* value = [NSNumber numberWithDouble:accuValue];
    onScreenTextValue =[value stringValue];
    [self displayOnScreenValue];
    opJustSet = YES;
    [value release];
    

    You should not release value. You only need to release if you called alloc, a copy method,
    or if you called retain on it. Most messages return an object that will be autoreleased.

    Same goes for this

     [pressedOpp release];
    

    remove it — you didn’t alloc pressedOpp (or retain it)

    Also, I don’t know what onScreenTextValue is, but it should probably be an @property with (retain). If so, you need to access like this:

     self.onScreenTextValue = [value stringValue];
    

    To get the automatic retaining (in Objective-C self.name and name are not the same thing — the first one uses the property and the second is raw access to the field, which bypasses the generated setter)

    1. Familiarize yourself with reference counting semantics

      http://www.loufranco.com/blog/files/managing-memory-iphone.html

    2. -or- Upgrade to latest Xcode and use automatic reference counting.

    One other simple thing to do is to always run "Build and Analyze" and make sure to fix every single problem. It’s really good at finding incorrect releases (in fact, this same code is what’s behind automatic reference counting)

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

Sidebar

Related Questions

Ok, I am a complete beginner to this, in fact I am still building
I'm following this tutorial about building a blog with node.js, express and mongodb. The
Absolute beginner question: I have a template file index.html that looks like this: ...
A beginner's question, probably a trivial one. Here's the XUL code snippet: <window xmlns=http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul>
I am beginner in MVC3 and building one application, i need to make confirmation
I am a beginner coder, i am building a project using C# Asp.Net in
I am a beginner to android, i am building a application in which when
Beginner page building question: I've got a simple /div container defined via a CSS
I am a java beginner and for my first project I started building a
I am beginner in C# programming. I have encountered small problem during building application

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.