我有以下代码,其中每个对象都是UISwitch IBOutlet属性。我也不确定为什么当使用xcode分析器时,我为每一行都收到了内存泄漏警告。针对UISwitch的Stactic分析器内存泄漏警告
- (IBAction)copyEntirePreviousNoteButtonClicked:(id)sender
{
self.myUISwitch1.on = TRUE;
self.myUISwitch2.on = TRUE;
}
- (IBAction)updateButtonClicked:(id)sender
{
NSMutableDictionary *copyOptions = [[[NSMutableDictionary alloc] init] autorelease];
if (self.myUISwitch1.on) {
[copyOptions setValue:@"ON" forKey:@"myUISwitch1"];
}
if (self.myUISwitch2.on) {
[copyOptions setValue:@"ON" forKey:@"myUISwitch2"];
}
}
更新与全码:
@property (nonatomic, retain) IBOutlet UISwitch *copy_hp_cchpi;
@property (nonatomic, retain) IBOutlet UISwitch *copy_hp_history;
- (IBAction)copyEntirePreviousNoteButtonClicked:(id)sender
{
self.copy_hp_cchpi.on = YES;
self.copy_hp_history.on = TRUE;
}
- (IBAction)updateButtonClicked:(id)sender
{
NSMutableDictionary *copyOptions = [[[NSMutableDictionary alloc] init] autorelease];
if (self.copy_hp_cchpi.on) {
[copyOptions setValue:@"ON" forKey:@"copy_hp_cc_history_present_illness"];
}
if (self.copy_hp_history.on) {
[copyOptions setValue:@"ON" forKey:@"copy_hp_med_fam_social_history"];
}
int rcode = [MyAPIDataSource copyPreviewAppointmentClinicalInfo:[MyAPIDataSource getCurrentAppointmentId] copyOptions:copyOptions];
if (rcode)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Failed to copy last appointment information. Please try again." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
else
{
//Send Notifications to other screens that clinical info was copied from last appointment to current one.
[[NSNotificationCenter defaultCenter] postNotificationName:@"LastAppointmentLoadedHandler" object:self];
[self dismissModalViewControllerAnimated:YES];
}
}
哪一行是你得到的警告,是你的代码看起来像什么,或者你是否将它编辑为StackOverflow - 你的updateButtonClicked方法只是创建一个NSMutableDictionary然后抛出它。 –
myUISwitch1和myUISwitch2如何声明@properties,如果是这样的话,还有whoa属性。可能提供的代码将是最好的。 – zaph
他们是保留和nonatomic属性proerties。它们在dealloc中发布。代码被压低了一点,之后NSMutableDictionary被上传到服务器。 – Jon