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

The Archive Base Latest Questions

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

Instruments is reporting all the leaks of this VC in this method. What could

  • 0

Instruments is reporting all the leaks of this VC in this method. What could be the reason? I think it’s the alloc, but don’t know why is leaking.

- (void)loadViewContent
{
    switch (self.currentView) 
    {
        case 0:
            self.title = @"Title 1";
            [self.navigationItem.backBarButtonItem release]; //para evitar un memory leak
            self.navigationItem.backBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Blood" style:UIBarButtonItemStylePlain
                                                                                     target:nil action:nil] autorelease];

            [tableContent addObject:@"0"];
            [tableContent addObject:@"1 - 49"];
            [tableContent addObject:@"50 - 75"];
            [tableContent addObject:@"76 - 89"];
            [tableContent addObject:@"More than 89"];
            break;

        case 1: 
            self.title = @"Title 2";
            [self.navigationItem.backBarButtonItem release]; 
            self.navigationItem.backBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Resp. Rate" style:UIBarButtonItemStylePlain
                                                                                     target:nil action:nil] autorelease];

            [tableContent addObject:@"0"];
            [tableContent addObject:@"1 - 5"];
            [tableContent addObject:@"6 - 9"];
            [tableContent addObject:@"More than 29"];
            [tableContent addObject:@"10 - 29"];
            break;

        default:
            break;
        }
    }

enter image description here

Thanks in advance!

  • 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-25T10:26:46+00:00Added an answer on May 25, 2026 at 10:26 am

    The following code definitely leaks (assuming a memory model of copy or retain on the property tableContent):

    self.tableContent = [[NSMutableArray alloc] init];
    

    The setter of tableContent will release the old value and retain / copy / assign the new value. Consider a statement like:

    self.tableContent = [NSMutableArray array];
    

    This is perfectly valid because [NSMutableArray array] is an autoreleased object. Subsequent uses of self.tableContent only work after this because the setter of tableContent increments the retain count preventing tableContent from being released.

    Your code (as weird as this seems) should be like the following:

    self.tableContent = [[NSMutableArray alloc] init];
    [self.tableContent release];
    

    OR – requires using an autoreleased object which some devs like to avoid where possible

    self.tableContent = [[[NSMutableArray alloc] init] autorelease];
    

    OR – uses an unnecessary temp variable to clarify memory management

    NSMutableArray * tempArr = [NSMutableArray alloc];
    self.tableContent = tempArr;
    [tempArr release];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Instruments' Leaks tells me that this UIImage is leaking: UIImage *image = [[UIImage alloc]
So Instruments tells me I have three memory leaks originating in this method (specifically,
Instruments tells me there's a mem leak in this code, but I can't seem
I am trying to locate leaks using instruments, but the leaks I see there
Instruments is reporting me a leak of a NSDate variable. But If I add
While using Instruments, it seems like there is a leak coming from this method
Quick question, Instruments is reporting a leak here... MyViewController *myVC = [[MyViewController alloc] initWithNibName:@myView
I know this is a long-shot, but since I need this code to work,
Instruments leaks says that this code leaks: NSString *name = [file substringToIndex:i]; Layer *actualLayer
Running Instruments on my iPad app found 2 leaks, except I cannot understand where

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.