我的代码有问题。我正在使用performance tool运行我的应用程序,这样我就可以看到我的代码使用了多少内存。当我使用UINavigationController的popViewController方法时,分配的位置似乎没有释放,即使我已经使用"self.myarray =nil“释放了viewDidUnload方法中的所有对象;"myarray”是在实现文件中合成的。导致这种情况的原因可能是什么?
显示警报视图时,它会增加已分配的内存。没问题的。但是,即使我点击了ok按钮,它也不会释放分配的内存。
AlertView部件的示例代码在此处。
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Seri Seçilmedi"
message:@"Lütfen bir seri seçiniz."
delegate:self
cancelButtonTitle:@"Tamam"
otherButtonTitles:nil];
[alert show];
[alert release];发布于 2011-01-28 21:32:10
在出现内存警告的情况下将调用viewDidUnload,但在使用popViewController时不会调用。您应该释放dealloc方法中的对象。
发布于 2011-01-28 22:15:04
就我使用它们而言,我已经在phix23提到的dealloc()中释放了它。
if(self.alert.visible) {
[self.alert dismissWithClickedButtonIndex:-1 animated:NO];
}
[alert release];
self.alert = nil;发布于 2011-08-06 01:24:24
if(self.alert.visible) {
[self.alert dismissWithClickedButtonIndex:-1 animated:NO];
}
[alert release];//If you only do [alert release], you will release the memory, but the alert still point to the memory
self.alert = nil; // alert no longer exists.如果您只是释放一个对象,那么它将成为释放的对象。
如果你在释放的对象上执行任何操作,你的应用程序就会崩溃。为了避免这种情况,总是首选“释放对象后将其赋值为nil”。因为我们都知道在nil上执行的任何操作都不会被执行:)
或者,您可以设置自动释放
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Seri Seçilmedi"
message:@"Lütfen bir seri seçiniz."
delegate:self
cancelButtonTitle:@"Tamam"
otherButtonTitles:nil]autorelease];https://stackoverflow.com/questions/4828723
复制相似问题