Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Watch kit App : Terminated due to memory error

Hi I am developing an app in which I require to chache 50 images (size of all images is 2.5 mb) ,It is chaching the images but also increases the memory by 10 mb in Apple Watch App due to which app crashes .

Xcode gives error in xCode “Message from debugger: Terminated due to memory error”

The code i am 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 the screenshot of Memory allocation and memory leak is :

enter image description here

Please Help, Thanks in advance .

like image 286
h.kishan Avatar asked Nov 09 '22 13:11

h.kishan


1 Answers

  • Are any of your images actually animations (that would use up more space)?
  • Collect the return value of each call to addCachedImage(). False means it could not be added -- you need to check to that and it might give clues as to a particular problem image.
  • Before calling anything, try to empty the cache, removeAllCachedImages. This means you will be clean from previous cache interactions using up the pool of memory.

I think your problem is not a leak, I think your problem is over-retained allocations. So use the Allocations tool (with retain count tracking) to see how much memory was allocated (VM allocations) and how many entities are holding on to such memory (retain counts).

like image 58
Faisal Memon Avatar answered Nov 14 '22 21:11

Faisal Memon