如果我使用ARC,-didReceiveMemoryWarning是否有用?

Bri*_*acy 2 memory-management objective-c ios

当我UIViewController在Xcode中创建一个新的子类时,它带有默认方法,如initviewDidLoad.最后一个是didReceiveMemoryWarning.这让我想到,如果我使用ARC,我应该担心吗?这是默认方法.

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
Run Code Online (Sandbox Code Playgroud)

这里的关键字是dispose.由于我release在使用ARC时无法显式调用任何对象,我是否应该实现此方法?

rma*_*ddy 6

是.使用ARC或MRC没有区别.无论哪种方式,您的应用程序都可能获得内存警告 使用它didReceiveMemoryWarning来清理你可以使用的任何内存,如清空缓存或诸如此类的东西.

您仍然可以清除ARC下的对象,以便取消分配它们.您只需要删除对象的所有引用.