新闻中心

EEPW首页 > 嵌入式系统 > 设计应用 > iOS目前版本的内存管理差异有哪些呢?

iOS目前版本的内存管理差异有哪些呢?

作者:时间:2016-10-29来源:网络收藏

本文引用地址:http://www.eepw.com.cn/article/201610/306006.htm

说到技术那么大家都知道版本的升级那是在所难免的了,那么如果你是在学习的话那么也会有些关于版本的问题,这不前两天就有同学问老师:iOS目前版本的差异有哪些呢?如下就是我赢职场老师给学员的解答,由尚网小编整理希望对大家有所帮助。

iOS6.0以前版本

1

收到内存警告:调用 didReceiveMemoryWarning 内调用 super 的 didReceiveMemoryWarning 会将 controller 的 view 进行释放。所以我们不能将controller的view再次释放。

处理方法:

-(void)didReceiveMemoryWarning

{

[super didReceiveMemoryWarning];//如没有显示在window上,会自动将self.view释放。

// 6.0以前,不用在此做处理,self.view释放之后,会调用下面的viewDidUnload函数,在viewDidUnload函数中做处理就可以了。

}

-(void)viewDidUnload

{

// Release any retained subviews of the main view.不包含self.view

[super viewDidUnload];

//处理一些内存和资源问题。

}但是到了IOS 6.0之后,这里又有所变化,IOS 6.0内存警告的 viewDidUnload 被屏蔽,即又回到了IOS 6.0以前版本时期的方式。

收到内存警告:调用 didReceiveMemoryWarning 内调用 super 的 didReceiveMemoryWarning 调只是释放 controller 的 resouse,不会释放view。

处理方法:

-(void)didReceiveMemoryWarning

{

[super didReceiveMemoryWarning];//即使没有显示在window上,也不会自动的将self.view释放。

// Add code to clean up any of your own resources that are no longer necessary.

// 此处做兼容处理需要加上ios6.0的宏开关,保证是在6.0下使用的,6.0以前屏蔽以下代码,否则会在下面使用self.view时自动加载viewDidLoad

if ([self.view window] == nil)// 是否是正在使用的视图

{

// Add code to preserve data stored in the views that might be

// needed later.

// Add code to clean up other strong references to the view in

// the view hierarchy.

self.view = nil;// 目的是再次进入时能够重新加载调用viewDidLoad函数。

}



关键词: ios 内存管理

评论


相关推荐

技术专区

关闭