我正在构建一个应用程序来查看我从 API 中提取的照片。每张照片的大小约为 1MB。我设置了一个“幻灯片”来显示一张照片,然后转到下一张,就像用户实际使用该应用程序一样。我正在仪器中的 iPad 1 上进行测试。
当我的应用收到内存不足警告时,我将转储当前未向用户显示的所有照片,以及从 API 返回的所有缓存模型数据。我看到我在 Instruments 中的分配显着下降,虚拟内存使用也出现了类似的下降。即使消耗的内存有所下降,我的应用程序仍然被操作系统杀死。
应用程序响应 2-3 个内存警告而不会在被终止之前崩溃。
我最近切换到 ARC,所以也许有一些我不明白的地方?我认为将我的引用设置为 nil 就足够了。这是我的内存模型转储其图像数据的代码:
[[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationDidReceiveMemoryWarningNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) {
NSLog(@"Received memory warning; clear image for photo named \"%@\"", _name);
_image = nil;
_imageThumbnail = nil;
}];
哪个被调用。我还有一个 NSMutableDictionary,当我收到内存不足警告时,我正在调用 removeAllObjects。我在设备控制台中得到以下信息:
Oct 5 19:43:46 unknown configd[25] <Notice>: jetsam: kernel termination snapshot being created
Oct 5 19:43:46 unknown com.apple.launchd[1] <Notice>: (com.apple.accessoryd) Exited: Killed: 9
Oct 5 19:43:46 unknown com.apple.launchd[1] <Notice>: (com.apple.locationd) Exited: Killed: 9
Oct 5 19:43:46 unknown com.apple.launchd[1] <Notice>: (com.apple.mediaserverd) Exited: Killed: 9
Oct 5 19:43:46 unknown com.apple.launchd[1] <Notice>: (UIKitApplication:com.500px[0xd492]) Exited: Killed: 9
Oct 5 19:43:47 unknown kernel[0] <Debug>: launchd[1996] Builtin profile: accessoryd (sandbox)
Oct 5 19:43:47 unknown ReportCrash[1999] <Error>: libMobileGestalt loadBasebandMobileEquipmentInfo: CommCenter error: 1:45
Oct 5 19:43:47 unknown ReportCrash[1999] <Error>: libMobileGestalt copyInternationalMobileEquipmentIdentity: Could not get mobile equipment info dictionary
Oct 5 19:43:47 unknown ReportCrash[1999] <Error>: Saved crashreport to /Library/Logs/CrashReporter/LowMemory-2011-10-05-194347.plist using uid: 0 gid: 0, synthetic_euid: 0 egid: 0
Oct 5 19:43:47 unknown DTMobileIS[1655] <Warning>: _memoryNotification : <NSThread: 0x1cd31410>{name = (null), num = 1}
Oct 5 19:43:47 unknown DTMobileIS[1655] <Warning>: _memoryNotification : {
OSMemoryNotificationLevel = 0;
timestamp = "2011-10-05 23:43:47 +0000";
}
Oct 5 19:43:47 unknown DTMobileIS[1655] <Warning>: _memoryNotification : <NSThread: 0x1cd31410>{name = (null), num = 1}
Oct 5 19:43:47 unknown DTMobileIS[1655] <Warning>: _memoryNotification : {
OSMemoryNotificationLevel = 0;
timestamp = "2011-10-05 23:43:47 +0000";
}
Oct 5 19:43:48 unknown com.apple.locationd[1997] <Notice>: locationd was started after an unclean shutdown
Oct 5 19:43:49 unknown SpringBoard[29] <Warning>: Application '500px' exited abnormally with signal 9: Killed: 9
有谁知道为什么我的应用程序被杀死,即使它正在释放内存?