Reputation: 345
I have multiple View Controllers set up that have a UIDatePicker in each view. I began testing using the Leaks tool and there are no Leaks from the date picker. Next I began testing using the allocations tool and this is where I'm finding all of the problems. Every each date picker is initialized in viewDidLoad I set the datepicker mode like this:
datePicker.datePickerMode = UIDatePickerModeDate;
Each time a View Controller that contains a date picker is displayed there are multiple allocations of "Malloc 392 KB" which eventually leads to the crash of the app. When digging deeper in the allocations tool it states that the responsible caller is [UISectionRowData:RefreshWithSection....]. I'm not sure how to approach this and fix it. Any help would be great. Attached are some screenshots from the allocations tool.
Upvotes: 3
Views: 915
Reputation: 5228
Try making your UIDatePicker
through coding. And initialize it when it is needed, do not initialize it in viewDidLoad
or viewWillAppear
say you have a button, when it is tapped you initialize UIDatePicker
.
And when user is finished selecting date remove it from superview and datePicker=nil;
. In that way you can save memory it will only be used as long as UIDatePicker is visible.
Upvotes: 1
Reputation: 2186
I think the line
datePicker.datePickerMode = UIDatePickerModeDate;
is probably misleading and it's probably the next line causing the leak
date.inputView = datePicker;
my guess would be date has a synthesized inputView variable which is retaining the object. Given you're doing alloc and init and no autorelease on this line...
datePicker = [[UIDatePicker alloc]init]
I'd expect this is the leak but hard to say as you may be calling release later but if not this would be my guess.
Upvotes: 1