繁体   English   中英

iPhone应用程序开发的内存问题

[英]Memory issue with iphone app development

我正在开发一个使用非常简单的界面并在后端进行数据库处理的iphone应用程序。 我也启用了ARC OPTION。 我的viewDidLoad方法如下:

    - (void)viewDidLoad
   {
    [super viewDidLoad];
// Do any additional setup after loading the view from its nib.

/*********needed to implement scroll view********/
svScroll.frame = CGRectMake(0, 0, 320, 460);
svScroll.contentSize = CGSizeMake(320, 800);
/*********************************************/

//[DataHelper openDbCompany];

NSString *date=[DataHelper getFinYr];

[btDate setTitle:[DataHelper dateSqliteToNormal:date] forState:UIControlStateNormal];

arrayUnitsMeasure=[[NSMutableArray alloc]initWithArray:[DataHelper getUnitsOfMeasure]];

//[DataHelper closeDbCompany];

tfValue.keyboardType=UIKeyboardTypeDecimalPad;
tfQuantity.keyboardType=UIKeyboardTypeDecimalPad;
tfCostUnit.keyboardType=UIKeyboardTypeDecimalPad;

//catching the notification for text field value change.
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(textFieldChanged:) name:UITextFieldTextDidChangeNotification object:tfQuantity];

[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(textFieldChanged:) name:UITextFieldTextDidChangeNotification object:tfCostUnit];

    }

我的.h文件包含包含IBOutlet,它们的定义如下:

    @interface
     Create_Inventory_Item:UIViewController<Date_Picker_Protocol,Picker_View_Protocol,UITextFieldDelegate>
    {
        IBOutlet UIScrollView *svScroll;
        IBOutlet UITextField *tfItemName;

IBOutlet UILabel *lbUnitsOfMeasure;
IBOutlet UIButton *btSelectUnitsMeasure;

IBOutlet UIButton *btDate;
IBOutlet UINavigationBar *btBack;

IBOutlet UITextField *tfQuantity;
IBOutlet UITextField *tfCostUnit;
IBOutlet UITextField *tfValue;

IBOutlet UIButton *btCreate;
NSMutableArray *arrayUnitsMeasure;

UIButton *btKeyboardDone;
UIView *accessoryView;
UITextField *txtActiveField;
UIButton *btMinus;
Picker_View *callPickerView;
Date_Picker *callDatePicker;
    }

    @property(nonatomic,retain) UIButton *btMinus;
    @property(nonatomic,retain)UITextField *txtActiveField;
    @property(nonatomic,retain) UIButton *btKeyboardDone;
    @property(nonatomic,retain)UIView *accessoryView;
    @property(nonatomic,retain) IBOutlet UINavigationBar *btBack;
    @property(nonatomic,retain)IBOutlet UIScrollView *svScroll;
    @property(nonatomic,retain)IBOutlet UITextField *tfItemName;
    @property(nonatomic,retain)IBOutlet UILabel *lbUnitsOfMeasure;
    @property(nonatomic,retain)IBOutlet UIButton *btSelectUnitsMeasure;
    @property(nonatomic,retain) IBOutlet UIButton *btDate;
    @property(nonatomic,retain) IBOutlet UITextField *tfQuantity;
    @property(nonatomic,retain) IBOutlet UITextField *tfCostUnit;
    @property(nonatomic,retain)IBOutlet UITextField *tfValue;
    @property(nonatomic,retain) IBOutlet UIButton *btCreate;

    -(IBAction)btSelectUnitsMeasure:(id)sender;
    -(IBAction)btDate:(id)sender;
    -(IBAction)btCreate:(id)sender;
    -(IBAction) hideKeyboard:(id)sender;
    -(IBAction)showAlerView:(NSString *)message;
    -(IBAction)btBack:(id)sender;

请告诉我在dealloc和viewDidUnloadMethod中需要做什么? 我正在使用ARC OPTION。
另外,当我在模拟器中使用配置文件选项运行应用程序以进行内存分配和泄漏时,有时会显示MEMORY LEVEL LOW WARNING和MEMORY LEVEL NORMAL。 这是什么原因?

如果使用的是ARC,则只需要取消分配即可使该类实例中所有基于对象的成员无效。

所有应用程序偶尔都会收到内存警告。 您可以选择通过使以后可以延迟初始化的成员无效来进行响应。

在我的应用中,我在viewWillAppear中延迟初始化了大多数可视成员(UIViews等),并在viewDidDisappear方法中积极释放。 这样,只有2个视图可以一次初始化其成员(在视图控制器转换期间),而只有1个视图是唯一可见的视图。

结果,除了处理大型图像之类的信息时,我几乎没有收到任何内存警告。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM