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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:56:58+00:00 2026-05-22T16:56:58+00:00

I have made a sample project that reproduces this issue which contains two views:

  • 0

I have made a sample project that reproduces this issue which contains two views:

root header:

#import <UIKit/UIKit.h>
#import "view2.h"

@interface RootViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>{
    view2 *secondView;
    UITableView *table;
    NSArray *array;
}

@property (nonatomic, retain) view2 *secondView;
@property (nonatomic, retain) IBOutlet UITableView *table;
@property (nonatomic, retain) NSArray *array;
@end

root main:

#import "RootViewController.h"

@implementation RootViewController
@synthesize table, array, secondView;

- (void)viewDidLoad
{
    [super viewDidLoad];    
    if(self.array == nil){
        self.array = [NSArray arrayWithObjects:@"1", @"2", @"3", @"4", nil];
    }
}
- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

}

- (void)viewDidUnload
{
    [super viewDidUnload];
    table = nil;
    array = nil;
    secondView = nil;

}

- (void)dealloc
{
    [table release];
    [array release];
    [secondView release];
    [super dealloc];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [array count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    cell.textLabel.text = [array objectAtIndex:indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    if (secondView == nil) {
        secondView = [[view2 alloc] init];
    }
    [self.navigationController pushViewController:secondView animated:YES]; 
}
@end

view2 simple contains a label with the text “view 2” for identification purposes.
All this code is doing in the root controller is creating an array with the values 1,2,3,4 and binding this text as rows to the table, clicking any row pushes view 2 onto the stack.
if you load up the app in the simulator using the leaks instruments tool, click on any row so that view2 is displayed and then simulate an error warning the following leaks appear:
image
for the line:

self.array = [NSArray arrayWithObjects:@"1", @"2", @"3", @"4", nil];

this is causing me a lot of problems in my main app as i am using arrays to provide data in tables all over the place.

i have tried various ways to fix this such as declaring the array in different ways to no avail.

any help is greatly appreciated!

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-22T16:56:59+00:00Added an answer on May 22, 2026 at 4:56 pm

    In viewDidUnload you’re mixing up property vs. direct ivar access.

    array = nil simply sets the ivar to nil without using the synthesized accessor method. You have to use the dot notation: self.array = nil;

    This way the accessor setArray: is used which handles memory management for you.

    Mixing up ivars and properties is a frequent problem amongst Objective-C beginners. The confusion can easily be prevented by always using different names for properties and ivars:

    @synthesize array = _array;
    

    You can just leave out the ivar declaration in the class’s @interface or name it as in the @synthesize directive.

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

Sidebar

Related Questions

I have made a sample application which constructs a filter graph to capture audio
I have made a simple test application for the issue, two winforms each containing
I have made a little framework for php. In this project I have the
This is a simplified version of a class that I have in my project.
I came across a comment this answer which states that a library project: cannot
I have started using jQuery and rails. I have made a simple form that
I have a simple software that is made in Delphi 7, and it crashes
I have some code that does something like this (Irrelevant bits snipped): void foo(Bitmap
I've made a small example with a Person class, which contains a list of
I've made a simple project to illustrate my problem. I have a user control

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.