I've build (must be simple...) MVC model, but I still have memory leak when pushing back button.
Model class: .h
@interface Nominal : NSObject {
int nominalID;
NSString *nominal;
NSString *nominalImg;
NSString *nominalName;
}
@property(nonatomic)int nominalID;
@property(nonatomic,retain)NSString *nominal;
@property(nonatomic,retain)NSString *nominalImg;
@property(nonatomic,retain)NSString *nominalName;
@end
.m
@implementation Nominal
@synthesize nominal,nominalID,nominalImg,nominalName;
-(void)dealloc
{
[self.nominal release];
[self.nominalImg release];
[self.nominalName release];
}
@end
I do release the strings as well.
In my view class I populate it so:
.h
@interface Nominals : UIViewController {
...
NSMutableArray *nominalsArr;
...
}
@property(retain,nonatomic)NSMutableArray *nominalsArr;
.m
- (void)viewWillAppear:(BOOL)animated
{
[[self navigationController]setToolbarHidden:YES animated:YES];
DBAccess *dbAccsess=[[DBAccess alloc]init];
self.nominalsArr=[dbAccsess returnNominals:subCountryID];
[dbAccsess closeDataBase];
[dbAccsess release];
[super viewWillAppear:animated];
}
- (void)dealloc
{
[nominalsArr release];
[self.navigationController release];
[super dealloc];
}
Looks like I do release the whole bundle of holy things, but when I push pack button from this view to previous, the memory leak pops up:
What I'm doing wrong?
You help is utterly appreciated.
You've forgotten a
[super dealloc]
in[Nominal -dealloc]
. Also, don't call[self.navigationController release]
as that property is already handled by the superclass (UIViewController
).