1

I am developing an iphone application which uses very simple interface and does database handling at the backend. I am enabling ARC OPTION as well. My viewDidLoad method is as follows:

    - (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];

    }

My .h file contains contains IBOutlets which are defined as follows:

    @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;

Please tell me what do I need to do in dealloc and viewDidUnloadMethod? I am using ARC OPTION.
Also, when I run the app with profile option in simulator for memory allocation and leak, it sometimes shows MEMORY LEVEL LOW WARNING and MEMORY LEVEL NORMAL. What is the cause of this?

Toon Krijthe
  • 52,876
  • 38
  • 145
  • 202
abhishek behl
  • 23
  • 1
  • 8

1 Answers1

0

If you're using ARC you just need a dealloc that nullifies all the object-based members in that class instance.

All apps get memory warnings once in a while. You can choose to respond by nullifying members that can be lazy-initialized later.

In my apps I lazy-initialize most visual members (UIViews etc...) in viewWillAppear and aggressively release in the viewDidDisappear method. This way only 2 views can have their members initialized at once (during view controller transitions) and only 1 view when that view is the only visible one.

As a result I get very few memory warnings, except for when manipulating big images and such.

Jason Fuerstenberg
  • 1,341
  • 13
  • 13
  • do i need to make a call to [super dealloc] in dealloc method?? – abhishek behl Sep 06 '12 at 05:34
  • Not if you're using ARC you don't need to. – Jason Fuerstenberg Sep 06 '12 at 06:00
  • What do you mean by 'aggresive releasing'?How do i release in ARC? Please explain? Also, what all object should be set to nil in ARC? Please look into the code snippet and tell me object names. – abhishek behl Sep 18 '12 at 16:43
  • Aggressive means release early. In ARC, set references to object you won't likely need to "nil" as early as possible. If you're lazy-initializing things just in time you can afford to release things early as well. This keeps your apps lean on memory requirements. – Jason Fuerstenberg Sep 19 '12 at 01:21