Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 07-01-2011, 04:48 PM   #1 (permalink)
Registered Member
 
Join Date: Jul 2009
Location: North America
Posts: 53
shimmy is on a distinguished road
Default dealloc on tableViewContoller causing crash when using popViewController on NavContr

Hi

I have a table view with a list of cells (which have sliders and labels in them, so not typical cells, but I think everything is released there when necessary, but I've always been a bit confused by tableViews: eg in this code, the list is short and I had trouble with it, so I gave all the cells custom identifiers so they wouldn't try to reuse them... Is that really bad? The list is only about 10 items long) and I replaced the default back button with a bar button system Cancel button and an alert that confirms you want to cancel and discard all changes. The cancel button links to a function which puts up the alert and then a delegate function calls the pop view controller on the navigation controller. It successfully goes back to the previous view, but then after a second it crashes. I added NSZombieEnabled and it showed me that the app was crashing on [super dealloc]; in the popped view controller's dealloc function. I would try to do it without using the pop, but the fact that this doesn't work probably means there is a bug in my memory management but I am not sure where.

The error said: Thread 1: Program received signal "EXC_BAD_ACCESS"

There seems to be a few people with similar issues, but no definitive answers that solve the problem.

The push onto the navigation controller stack from the first view controller
Code:
-(IBAction) beginNewTest {
    NSLog(@"Beginning new test.  FirstViewController.m");
    TestListViewController* testListViewController = [[TestListViewController alloc] init];
    testListViewController.title = @"New Test";
 
    [self.navigationController pushViewController:testListViewController animated:YES];
    [testListViewController release];
    
    NSLog(@"Complete initialization and loading of test list view controller.  Pushed onto navigation stack.  FirstViewController.m");
}

//the init function in the TestListViewController


-(id) init {
    if (self = [super initWithStyle: UITableViewStylePlain]) {
        //initialize here
        UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelTest)];  //make it cancel
        [self.navigationItem setHidesBackButton:TRUE];
        [self.navigationItem setLeftBarButtonItem:cancelButton];
        [cancelButton release];
    }
    return self;    
    
}


//The problem occurs with or without the alertview, so that's not causing it...  

-(void) cancelTest {
    NSLog(@"Cancelling test  TestListViewController.m");
    UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Canceling Test" message:@"Are you sure you want to cancel the test?  All unsaved data will be lost." delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
    [alert show];
    [alert release];
    
}
-(void) alertView: (UIAlertView *)alertView clickedButtonAtIndex: (NSInteger)buttonIndex {
    if (buttonIndex == 1)
        [self.navigationController popViewControllerAnimated:YES];
    else
        return;
}


//Here's the dealloc
- (void)dealloc {
	NSLog(@"Dealloc function reached.  TestListViewController.m");
    [scoreForTest release]; //an ns dictionary allocated in viewdidload
    
    [super dealloc]; //crashes here acc. to NSZombieEnabled
}
Any ideas?

Thanks!

Last edited by shimmy; 07-03-2011 at 12:14 PM. Reason: used code tags
shimmy is offline   Reply With Quote
Old 07-01-2011, 06:57 PM   #2 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

I love it when people show everything except what is important. Like this:

Code:
[scoreForTest release]; //an ns dictionary allocated in viewdidload
So, perhaps you should show that.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 07-03-2011, 10:09 AM   #3 (permalink)
Registered Member
 
Join Date: Jul 2009
Location: North America
Posts: 53
shimmy is on a distinguished road
Default

Quote:
Originally Posted by BrianSlick View Post
I love it when people show everything except what is important. Like this:

Code:
[scoreForTest release]; //an ns dictionary allocated in viewdidload
So, perhaps you should show that.
Code:
- (void)viewDidLoad {
    [super viewDidLoad];
	startDateTime = [NSDate date]; //get start time, and will compare with end time to determine time to score.  May want to only set this after first score has been altered
	if (scoreForTest == nil) {
		//dictionary with integer values for scores (initialized to -1 so no ambiguity)
		NSArray* arrayOfScores = [NSArray arrayWithObjects:[NSNumber numberWithInt:-1], [NSNumber numberWithInt:-1], [NSNumber numberWithInt:-1],
															[NSNumber numberWithInt:-1], [NSNumber numberWithInt:-1], [NSNumber numberWithInt:-1],
															[NSNumber numberWithInt:-1], [NSNumber numberWithInt:-1], [NSNumber numberWithInt:-1],
															[NSNumber numberWithInt:-1], nil];
		
		scoreForTest = [[NSMutableDictionary alloc] initWithObjects:arrayOfScores forKeys:self.arrayOfTestTitles];
	}
	self.editing = NO;
	UIButton* infoButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
	[infoButton addTarget:self action:@selector(requestHelp:) forControlEvents:UIControlEventTouchUpInside];
	[infoButton setFrame:CGRectMake(10, 0, 20, 20)];
	UIBarButtonItem *infoBarButton = [[UIBarButtonItem alloc] initWithCustomView:infoButton];
	self.navigationItem.rightBarButtonItem = infoBarButton;
	

	[infoButton release];
}
shimmy is offline   Reply With Quote
Old 07-03-2011, 10:39 AM   #4 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

infoButton should not be released, and I suggest you read the properties link in my signature.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 07-03-2011, 11:26 AM   #5 (permalink)
Registered Member
 
Join Date: Jul 2009
Location: North America
Posts: 53
shimmy is on a distinguished road
Default

Quote:
Originally Posted by BrianSlick View Post
infoButton should not be released, and I suggest you read the properties link in my signature.
Why shouldn't it be released?


EDIT: Oh sorry. It should be releasing inforBarButton, not infoButton.

EDIT 2: Reading through your properties guide -- very informative! Do you think this is causing my problems?

EDIT 3: The changes I made (releasing infoBarButton instead of infoButton and also modifying the allocation of score for test based on your guide) has fixed the problem! Thank you very much! I was always very confused by the memory management, especially with properties, and your guide has helped clear a lot of that up already. I suggest everyone take a look at it.

Last edited by shimmy; 07-03-2011 at 12:13 PM. Reason: added more detail , changes in status
shimmy is offline   Reply With Quote
Reply

Bookmarks

Tags
dealloc, memory, navigation controller, popviewcontroller, table view

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 346
9 members and 337 guests
apatsufas, chemistry, lendo, leostc, Leslie80, lzwasyc, MarkC, SamorodovAlex, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,664
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Leslie80
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:32 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0