【发布时间】:2012-10-01 13:40:26
【问题描述】:
我似乎有一个泄漏的 UIDatePicker。我已经注意到将 datePickerMode 设置为显示日期和时间的内存泄漏。但是,我只是想显示日期。我相当肯定这是一个框架泄漏,因为当我注释掉几个 UIDatePicker 属性分配时,泄漏就消失了。此代码泄漏 1 个 CGColor 对象和 1 个 UIDeviceRGBColor 对象:
datePicker = [[UIDatePicker alloc] initWithFrame:[self detailViewRect]];
datePicker.datePickerMode = UIDatePickerModeDate; //leaks CGColor when setting this
datePicker.hidden = NO;
datePicker.timeZone = [NSTimeZone systemTimeZone]; //leaks UIDeviceRGBColor
datePicker.maximumDate = [NSDate date];//leaks UIDeviceRGBColor
datePicker.autoresizingMask = UIViewAutoresizingFlexibleWidth;
通过评论 Instruments 报告为违规的行,我没有发现任何泄漏:
datePicker = [[UIDatePicker alloc] initWithFrame:[self detailViewRect]];
//datePicker.datePickerMode = UIDatePickerModeDate; //leaks CGColor when setting this
datePicker.hidden = NO;
//datePicker.timeZone = [NSTimeZone systemTimeZone]; //leaks UIDeviceRGBColor
//datePicker.maximumDate = [NSDate date];//leaks UIDeviceRGBColor
datePicker.autoresizingMask = UIViewAutoresizingFlexibleWidth;
至少没有设置日期模式,UIDatePicker 毫无价值。有人有解决方法吗?
【问题讨论】:
-
您检查过设备上的泄漏吗?还是只在模拟器上?有时模拟器存在设备上不存在的内存泄漏错误。
-
关于解决方法,泄漏有多严重?
-
@barley 感谢您的提醒。设备上没有泄漏。我没有使用ARC。每次释放日期选择器时,仪器都会报告 50B。我不希望用户频繁使用它。
-
有同样的问题。我启用了 ARC。如果用户不会经常使用日期选择器,这没什么大不了的。
标签: ios datepicker memory-leaks