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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:55:10+00:00 2026-05-23T23:55:10+00:00

This is the code, it doesn’t work when [unosUpisa release]; and [unosRazlike release]; are

  • 0

This is the code, it doesn’t work when [unosUpisa release]; and [unosRazlike release]; are entered;

How to properly release those unosUpisa and unosRazlike objects?

-(IBAction) padIliStilja: (id) sender
{
    NSNumber *unosUpisa = [[NSNumber alloc] init];
    NSNumber *unosRazlike = [[NSNumber alloc] init];
    if ([sender tag] == 1)
    {
    unosUpisa = [NSNumber numberWithInt: 162 + [Data variables].zvanja];
    unosRazlike = [NSNumber numberWithInt: 0];
    }
    else if ([sender tag] == 2)
    {
        unosRazlike = [NSNumber numberWithInt: 252 + [Data variables].zvanja];
        unosUpisa = [NSNumber numberWithInt: 0];
    }

    if ([Data variables].upisZaMi == NO)
    {
        [[Data variables].rezultatMi addObject: unosUpisa];
        [[Data variables].rezultatVi addObject: unosRazlike];
    }
    else
    {
        [[Data variables].rezultatVi addObject: unosUpisa];
        [[Data variables].rezultatMi addObject: unosRazlike];
    }

    [self dismissModalViewControllerAnimated: NO];
    [unosUpisa release];
    [unosRazlike 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-23T23:55:11+00:00Added an answer on May 23, 2026 at 11:55 pm

    You have to release every object that you own (you retained, copied, or init/alloced).
    The way you release your objects at the end is correct, but, here unosRazlike = [NSNumber numberWithInt: 0];, you assigned unosRazlike another value, without releasing the previous one, and here is a leak.
    Also, with this kind of method, you should retain your object.

    So :

    unosRazlike = ...
    // first
    [unosRazlike release];
    unosRazlike = [[NSNumber numberWithInt: 0] retain];
    // ...
    [unosRazlike release];
    

    EDIT

    -(IBAction) padIliStilja: (id) sender
    {
        // this is no matter
        NSNumber *unosUpisa = [[NSNumber alloc] init];
        NSNumber *unosRazlike = [[NSNumber alloc] init];
        if ([sender tag] == 1)
        {
            // don't forget to release them !
            [unosUpisa release]; [unosRazlike release];
            // and to retain (numberWithInt returns autoreleased object
            unosUpisa = [[NSNumber numberWithInt: 162 + [Data variables].zvanja] retain];
            unosRazlike = [[NSNumber numberWithInt: 0] retain];
        }
        else if ([sender tag] == 2)
        {
            // same again
            [unosUpisa release]; [unosRazlike release];
            // and to retain (numberWithInt returns autoreleased object
            unosRazlike = [[NSNumber numberWithInt: 252 + [Data variables].zvanja] retain];
            unosUpisa = [[NSNumber numberWithInt: 0] retain];
        }
    
        if ([Data variables].upisZaMi == NO)
        {
            [[Data variables].rezultatMi addObject: unosUpisa];
            [[Data variables].rezultatVi addObject: unosRazlike];
        }
        else
        {
            [[Data variables].rezultatVi addObject: unosUpisa];
            [[Data variables].rezultatMi addObject: unosRazlike];
        }
    
        [self dismissModalViewControllerAnimated: NO];
        [unosUpisa release];
        [unosRazlike release];
    }
    

    But just a thought… why initializing ‘blank’ number objects, if you set the value either in the if or in the else part ?

    Just declare them

    NSNumber *unosRazlike, *unosUpisa;
    

    and set their values in the if/else.

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

Sidebar

Related Questions

this code doesn't work why? private void web_FBCheck_Navigating(object sender, WebBrowserNavigatingEventArgs e) { if (web_FBCheck.Url.ToString()
setInterval in this code doesn't work properly <script language=javascript> x = y = 0;
I'm wondering why this code doesn't work: void KeyValueList::Release() { //(m_ppKeyValueList is a dynamic
Does anyone know why this code doesn't work. This means, the alert is NOT
Hey I have this code but it doesn't work because it is expecting a
The following code doesn't work! 'this' in in the context when i access it
I have this code that works in a unit test but doesn't work when
I thought this code would work, but the regular expression doesn't ever match the
Here's what I'm trying to do -- this is pseudo code and doesn't work.
This code doesn't work, anyone have any recommendations? Perhaps I did something wrong? Anyone

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.