2012-09-06 46 views
1

我正在開發一個使用非常簡單的界面並在後端進行數據庫處理的iphone應用程序。我也啓用ARC OPTION。 我viewDidLoad方法如下:iphone應用程序開發的內存問題

@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做:

- (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文件包含包含定義如下IBOutlets? 我正在使用ARC選項。
此外,當我在模擬器中運行帶有配置文件選項的應用程序以進行內存分配和泄漏時,它有時會顯示內存級別低警告和內存級別正常。這是什麼原因?

回答

0

如果您使用的是ARC,則只需要一個dealloc來取消該類實例中所有基於對象的成員。

所有應用程序都會在一段時間內收到內存警告。您可以選擇通過取消可稍後進行延遲初始化的成員來進行響應。

在我的應用程序中,我懶惰地初始化大多數視覺成員(UIViews等...)在viewWillAppear和積極釋放viewDidDisappear方法。通過這種方式,只有2個視圖可以同時初始化它們的成員(在視圖控制器轉換期間),並且只有1個視圖是該視圖唯一可見的視圖。

因此,我得到了很少的內存警告,除了操縱大圖像等時。

+0

我需要在dealloc方法中調用[super dealloc]嗎? –

+0

如果您使用的是ARC,則不需要。 –

+0

'aggresive release'是什麼意思?我如何在ARC中發佈?請解釋? 另外,所有的對象應該設置爲ARC在零?請查看代碼片段並告訴我對象名稱。 –