Understanding memory management with layers

Hello,

I have Watchface wich creates 3Layers in onIntialize() this works fine.

If the watch goes in sleep mode and comes back the layers seems not longer alive. The App crashes.

In case I create the Layers again I ran out of memory. This behavior is only seen in real live on the watch, not in Simulator.

Now I have to remove the layers from stack in onHide() and onExit() and set to null. In onShow() I have to recreate and redraw the layers.

Is this the right way to do it? Or is there a misunderstanding of the concept. 

Thank you

  • Sounds to me that it is the right way. If you have some data that is cachable, reusable (and takes some time to calculate) then maybe you can keep it a variable so it can be used to redraw the layers faster in case your app looses focus but then gets it back without the app being killed.

  • Do you observe this on an AMOLED watch? My watchface uses four layers on (some) MIP devices and I have not seen any issues like this. But MIP watches only have a low-power mode, so I guess they may behave differently. If it's an AMOLED watch, I'm curious what benefits you're getting from using layers, as opposed to just drawing the entire watchface every second?

  • I Use a fenix8 AMOLED. The layers are for saving time in onUpdate(). I have to draw the watch bezel only once in the background layer. Every second Iredraw only the WatchHands in the upper layer. The middle layer is for the additional date like HR.

    When the Watchface comes back from any other widget it crashes everything. The reallocation of the layers causes a out of memory error.

  • I don't have an AMOLED watch to play with, so can only speculate. Could it be that with three layers you're just too close to the memory limit? The graphics pool is limited too (and I think it's shared with other apps). What if you combine your upper and middle layers: draw the indicators first, then the watch hands; maybe with two layers it works?