0

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:

enter image description here

What I'm doing wrong?

You help is utterly appreciated.

NCFUSN
  • 1,624
  • 4
  • 28
  • 44
  • I don't think it's the cause of your problem, but it's usual if you've defined a property as `retain` to let the releases be done for you, i.e. `self.property = nil;` rather than sending a release message. – paulbailey Mar 03 '12 at 09:11
  • for NSStrings in model class? – NCFUSN Mar 03 '12 at 09:14
  • 1
    Well, usually for _all_ (or none if you prefer to release/clear the iVar) retained properties. Setting them to null will call release automatically. Just be sure to use the property (self.name) everywhere and not just set the iVar (name) to null or you'll get a leak. Renaming the iVars in @synthesize is a good idea to keep them straight. – Joachim Isaksson Mar 03 '12 at 09:24
  • @JoachimIsaksson is right, replace [self.nominal release] with self.nominal = nil; And self.nominalsArr = nil too... And navigationController.. Etc. Now, that is a strange leak, can you post the returnNominals method? – fbernardo Mar 03 '12 at 14:08
  • 1
    Don't use [self.x release] : http://stackoverflow.com/questions/7262268/why-shouldnt-i-use-the-getter-to-release-a-property-in-objective-c/7262360 – jrturton Mar 03 '12 at 14:12
  • @fbernardo Hello, again. It's not weird at all. Just really forgot to [super dealloc] in Model Class. That's all the evil. – NCFUSN Mar 03 '12 at 20:24
  • Nice one, missed it :) tip: always use the dealloc function xcode does for you. – fbernardo Mar 03 '12 at 21:11

1 Answers1

1

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).

MrMage
  • 7,282
  • 2
  • 41
  • 71