还请注意, UILocalNotification * notification = ... 声明了一个位于方法主体局部的新变量,该变量遮盖了您的 notification 属性.I have an issue that makes my application crash, and I have tried everything to change it, but with no luck. So I hope that a new set of eyes could help me out a little bit.Here is a view of my code:.h@property (nonatomic, retain) UILocalNotification *notification;.m- (void)applicationDidEnterBackground:(UIApplication *)application{ UILocalNotification *notification = [[UILocalNotification alloc] init]; notification.fireDate = [[NSDate date] dateByAddingTimeInterval:60*60*24]; notification.alertBody = @"Skal du ikke træne i dag? Det tager kun 7 minutter!"; [[UIApplication sharedApplication] scheduleLocalNotification:notification];}It gives me the following error when analyzing it:Potential leak of an object stored into 'notification'I really hope that one of you could help me out. Thanks! 解决方案 You need to -release or -autorelease the new notification. The succinct way to do this is:- (void)applicationDidEnterBackground:(UIApplication *)application{ UILocalNotification * notification = [[[UILocalNotification alloc] init] autorelease]; ^^^^^^^^^^^ notification.fireDate = [[NSDate date] dateByAddingTimeInterval:60*60*24]; notification.alertBody = @"Skal du ikke træne i dag? Det tager kun 7 minutter!"; [[UIApplication sharedApplication] scheduleLocalNotification:notification];}The system relies (heavily) on naming conventions. An initializer (e.g. -init), copier (copy, mutableCopy), and +new are examples of methods which return instances which you must release (or autorelease).Also note that UILocalNotification * notification = ... declares a new variable local to your method body, which shadows your notification property. 这篇关于Xcode:存储到“通知"中的对象的潜在泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-29 03:32