嗨,我正在开发一个应用程序,其中我需要chache 50张图像(所有图像的大小是2.5 MB),它正在追逐图像,但也因Apple应用程序崩溃而在Apple Watch App中增加了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)
Run Code Online (Sandbox Code Playgroud)
内存分配和内存泄漏的屏幕截图是:

请帮助,提前致谢.