Reputation: 862
I'm facing an annoying issue and I can't find out why.
I have a UIViewController I present in modal like that :
interviewsViewController *interviewsVC = [[interviewsViewController alloc] initWithNibName:nil bundle:nil];
[interviewsVC setManagedObjectContext:_managedObjectContext];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:interviewsVC];
[interviewsVC release];
[self presentModalViewController:navigationController animated:YES];
[navigationController release];
Then when I dismiss the view controller like this :
- (void)dismissViewController
{
[self dismissModalViewControllerAnimated:YES];
}
The dealloc gets called :
- (void)dealloc
{
[_managedObjectContext release];
[_interviewsArray release];
[scrollView release];
[pageControl release];
}
Once the view controller is dismissed, I send an memory warning via the iPhone Simulator Menu and the viewdidunload method gets called :
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
self.scrollView = nil;
self.pageControl = nil;
}
But there's always an error EXC_BAD_ACCES on the self.scrollView = nil ... More specifically at this line :
@synthesize scrollView;
And I can't find out why ?
If I add a breakpoint on the line above this one, the scrollView is not a zombie or equal to 0x0 ...
Do you have an idea ?
PS : Here's the header :
#import <UIKit/UIKit.h>
@interface interviewsViewController : UIViewController <UIScrollViewDelegate>
{
NSManagedObjectContext *_managedObjectContext;
NSMutableArray *_interviewsArray;
NSUInteger _fetchOffset;
CGFloat _lastXValue;
}
@property (nonatomic, retain) NSManagedObjectContext *managedObjectContext;
@property (nonatomic, retain) NSMutableArray *interviewsArray;
//IBOutlet
@property (nonatomic, retain) IBOutlet UIScrollView *scrollView;
@property (nonatomic, retain) IBOutlet UIPageControl *pageControl;
And I set the delegate of the scrollview in the XIB (not in the code).
Upvotes: 2
Views: 522
Reputation: 11839
You need to release properly in dealloc-
Use-
- (void)dealloc {
[_managedObjectContext release];
[_interviewsArray release];
self.scrollView = nil;
self.pageControl = nil;
[super dealloc];
}
ViewDidUnload also be used as that will be helpfull in case of low memory warnings.
Upvotes: 1