iOS:简单MVC模型中的内存泄漏 [英] iOS: Memory leak in simple MVC model

查看:106
本文介绍了iOS:简单MVC模型中的内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经建立了MVC模型(必须很简单...),但是按下按钮时仍然存在内存泄漏.

I've build (must be simple...) MVC model, but I still have memory leak when pushing back button.

模型类:.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

我也释放了琴弦.

在我的视图类中,它是这样填充的:

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:

我做错了什么?

我们非常感谢您的帮助.

You help is utterly appreciated.

推荐答案

您忘记了[Nominal -dealloc]中的[super dealloc].另外,请勿调用[self.navigationController release],因为该属性已由超类(UIViewController)处理.

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

这篇关于iOS:简单MVC模型中的内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆