【发布时间】:2015-07-31 05:17:43
【问题描述】:
您好,我正在开发一个应用程序,我需要在其中缓存 50 张图片(所有图片的大小为 2.5 mb),它正在缓存图片,但由于应用程序崩溃,Apple Watch 应用程序的内存也增加了 10 mb。
Xcode 在 xCode 中给出错误“来自调试器的消息:由于内存错误而终止”
我使用的代码如下:
for (var i : Int = 1; i<26; i++) {
let filenameHuman = NSString(format: "human_%d", i )
let filenameZombie = NSString(format: "zombie_%d", i )
var imageHuman : UIImage! = UIImage(named: filenameHuman as String)
var imageZombie : UIImage! = UIImage(named: filenameZombie as String)
WKInterfaceDevice.currentDevice().addCachedImage(imageZombie, name: filenameZombie as String)
WKInterfaceDevice.currentDevice().addCachedImage(imageHuman, name: filenameHuman as String)
}
NSLog("Currently cached images: %@",WKInterfaceDevice.currentDevice().cachedImages)
还有内存分配和内存泄漏的截图:
请帮忙,在此先感谢。
【问题讨论】:
-
这不会解决问题,但可能会有所帮助developer.apple.com/library/ios/qa/QA1894/_index.html
-
你有没有搞清楚这个。我有完全相同的问题。每次调用 WKInterfaceDevice.currentDevice().addCachedImage() 时内存都会增加,直到 AwakeWithContext 完成后才会释放。
-
@BrettHannah 我在 AwakeWithContext 完成后使用上面的代码,当我弹回来时,内存没有释放。 ?