在苹果文档中,你可以找到苹果建议在你的应用程序进入后台模式时释放重量级数据,例如图片。
如何从UIViews
和其他数据中释放图片?
如何以正确的方式从所有viewController
中释放UIViews
中的图片?
当应用程序接收到applicationWillResignActive
消息时,如何恢复数据?
如果有人有好的示例或链接,请展示出来。
在苹果文档中,你可以找到苹果建议在你的应用程序进入后台模式时释放重量级数据,例如图片。
如何从UIViews
和其他数据中释放图片?
如何以正确的方式从所有viewController
中释放UIViews
中的图片?
当应用程序接收到applicationWillResignActive
消息时,如何恢复数据?
如果有人有好的示例或链接,请展示出来。
在应用程序委托中添加两个方法
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[[NSNotificationCenter defaultCenter] postNotificationName:NOTIFICATION_APP_BACKGROUND object:nil];
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
[[NSNotificationCenter defaultCenter] postNotificationName:NOTIFICATION_APP_BACKGROUND object:nil];
}
- (id)init
{
self = [super init];
if (self) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillForeground) name:NOTIFICATION_APP_FOREGROUND object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appDidBackground) name:NOTIFICATION_APP_BACKGROUND object:nil];
}
return self;
}
- (void)appDidBackground {
}
- (void)appWillForeground {
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
让所有的视图控制器都从BaseViewController继承。在appDidBackground方法中,您应该释放不需要的数据,在appWillForeground方法中-恢复它
[UIImage imagenamed:@"image.png"]
- 这将不会释放图像内存。