Glance out of memory right after makeImageRequest

I'm writing a widget for CIQ 3.1.

In a Fenix 6 GlanceView instance, I've tried to makeImageRequest() with 2-color palette, of size about 170x60. The server will actually prepare a grayscale 1-bit monochrome png already. The png image size is about 300-400 bytes.

In simulator everything is just fine, and the bitmap is loaded up perfectly. Peak memory usage is less than 20KB. The problem is that once I sideload it to my F6pro it crashes every single time:

Error: Out Of Memory Error
Details: failed inside handle_image_callback
Time: 2019-12-18T06:13:24Z
Part-Number: xxx-xxxxx-xx
Firmware-Version: '5.00'
Language-Code: eng
ConnectIQ-Version: 3.1.6

I've tried to remove the :palette options in makeImageRequest() but it sometimes also crash in simulator saying out of memory too. If I reduce the server side image size a bit to 140x60 simulator is also fine, but on real device it still crashes due to out of memory.

This is really frustrating as the simulator really doesn't simulates things at all. 

Other annoying thing is that pressing "Select" (upper right) button on Simulator doesn't get into the "normal" view of the widget. It stays in to glance view forever. 

  • I found that my widget will trigger another makeImageRequest() in a Timer in some other code path, which downloads a 200x200 monochrome png of size 800-1000 bytes. That is why the out of memory happened. I remove that second png download in a glance view, and it works just fine on real device. 

    Somehow it can survive the simulator and memory view didn't catch what the makeImageRequest() may be doing in the background though. 

  • With further testing, it looks like even if I make sure only a single makeImageRequest() is made in GlanceView, it might still crash due to out of memory. The png I tried to download is always 200~400 bytes only. That's really confusing because in the simulator it won't crash.

  • When you run in the sim, make sure you've set 3.1.x as the target SDK in the run configuration.

    What is your memory usage before you do the makeImageRequest()? In glance view you can be at most 28kb 

  • Thanks for your reply. Yes I did set 3.1.x as the target SDK. I'll check the memory usage before/after makeImageRequest(). I am aware of the 28KB limit in other threads. 

    I've found that the out of memory crash isn't directly related to the png image size. For example, 316 bytes is fine, other times 275 bytes and 346 bytes crashed. All png images on my server are 1-bit monochrome though. 

    The crash log "inside handle_image_callback" suggests the out of memory condition happens either in the CIQ framework or inside the makeImageRequest()'s callback. In my callback I simply save it into a variable for onUpdate() to call drawBitmap(). 

  • What is the palette you set in the makeImageRequest?  Based on the , the image could be larger than you expect.

  • 18.3KB without makeImageRequest() in glance view.
    20.7KB with makeImageRequest() in glance view.

    From the View Memory Window the increased memory usage is only in code size and the bitmap variable (1966bytes).

    Palette is set to 0xFF000000 and 0xFFFFFFFF (black and white). 

    Somehow I cannot manage to crash my glance widget on my real device today. That's really weird. I'll update if I have anything.

  • I stopped development and kept using my half-done widget while going on holiday. For some unknown reason it never crashed on my F6pro for the past week or so!