Clock application: terminated due to a memory error

Hi, I am developing an application in which I need a chache of 50 images (the size of all images is 2.5 MB). It caches images and also increases the memory by 10 MB in the Apple Watch application, which is why the application crashes.

Xcode gives an error in xCode "Message from the debugger: terminated due to a memory error"

The code I'm using is below:

 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)

Also a screenshot of the memory allocation and memory leak:

enter image description here

Please help, thanks in advance.

+4
source share
2 answers
  • Are there any of your images that are actually animations (which will use more space)?
  • addCachedImage(). False , - , .
  • - , removeAllCachedImages. , , .

, , , . , Allocations ( ), , ( VM) ( ).

+1

, , , , .

for (var i : Int  = 1; i<26; i++) {
    autoreleasepool {
      /* code to cache images */ 
    }
}
0

All Articles