开发者

iPhone: Zombie object in modalview and delegate

开发者 https://www.devze.com 2023-04-06 10:56 出处:网络
I have a crash in my App that sometimes occurs, I tested with zombies enabled and this method it found as a ZOMBIE, this method usually works OK but in some conditions like lots of navigate back and f

I have a crash in my App that sometimes occurs, I tested with zombies enabled and this method it found as a ZOMBIE, this method usually works OK but in some conditions like lots of navigate back and forth at somepoint it crashes.

I ret开发者_开发百科ain the datepickerView in @property and release it in deaaloc.

iPhone: Zombie object in modalview and delegate


Set the datePickerDelegate to nil in dealloc. If it has a retain property after the first instantiation the delegate will probably have a dead reference in it and will randomly cause creates and crashes when Zombies are enabled. The crash happens because retain properties release the previous value and if it is a dead reference crashes ensue -- randomly. Also best to set delegates to assign, not retain.

Run in instruments, in Allocations set "Record reference counts" on on (you have to stop recording to set the option). Cause the picker to run, stop recording, search for there ivar (datePickerView), drill down and you will be able to see where all retains, releases and autoreleases occurred.

iPhone: Zombie object in modalview and delegate


I see no reason to keep the picker in memory after it has been popped from stack...

Instead of retaining the DatePickerController, remove "autorelease", and "release" just after presentSemiModalViewController, as per reednj post on SemiModelDatePicker

TDDatePickerController* datePickerView = [[TDDatePickerController alloc] 
                              initWithNibName:@"TDDatePickerController" 
                              bundle:nil];
datePickerView.delegate = self;
[self presentSemiModalViewController:datePickerView];
[datePickerView release];

Hopefully this will alleviate the problem. Otherwise, it could simply be a problem with the SemiModalDatePicker extension.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号