[英]How to manage memory with ARC mode
我正在创建ios应用程序,并且已启用ARC模式。 我正在将24个实例加载到ScrollView,但是在给定时间仅显示三个视图。 因此,我将删除已经加载到内存中的其他不需要的实例
if((NSNull *)[viewControllers objectAtIndex:2] != [NSNull null]) {
[viewControllers replaceObjectAtIndex:2 withObject:[NSNull null]];
[content3.view removeFromSuperview];
//remove third content page
[content3 viewDidUnload];
//set nil to instance to memory management
content3 = nil;
NSLog(@"Content 3 removed");
}
但是,当我使用事件探查器进行检查时,不会释放内存,它只会自动增加。
有人可以给我一些有关此问题的提示吗?
谢谢
我认为您的代码中存在很多问题:
viewDidUnload
。 切勿尝试执行此类操作,否则您将面临应用程序中的怪异行为。 检查以下代码:
if([viewControllers objectAtIndex:2] != [NSNull null])
{
[viewControllers replaceObjectAtIndex:2 withObject:[NSNull null]];
[content3.view removeFromSuperview];
content3 = nil;
NSLog(@"Content 3 removed");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.