Out of Memory error.

Let me start a new thread as the old one became very long and involved, and thanks Jim for your contributions.


The attached videos sum up the problem, showing the app crashing out of memory on the device but running continuously in the simulator with a Peak Memory of 109.1 kB.

The app is crashing at a line which is displaying a 550 byte PNG image.

What I have established so far.

According to the Devices.xml file, the fenix5 has 131,072 bytes, or 128kB of memory

Of which 124kB , or 126,976 bytes are available to the developer for code and program data. (so why tell us we have 128kB?)

When I run my app on the simulator, its Peak Memory is reported as 109.1kB (111,718 bytes).

When I add logging of memory used, before the crash line, the sim reports 107,816

and the app reports 120,744 (That's a massive 12,900 bytes difference.)

My question is: Why is my app crashing on the device, with 127,472 bytes of available memory when it apparently has (126,976 - 120,744 =) 6,232 bytes of memory to display a 550 byte png image?


https://youtu.be/SgU2MzJa7Bo

https://youtu.be/lnfaWpR6AzA


I am confident that as far as humanly possible, the two runs are using the same data. I have re-run the experiment many times with the same result running different data with the same result.

  • With the 128k vs 124k, that's just a difference in what the number means. (this started with CIQ2)

    By that I mean the FW allows 128k, but out of that 128k, about 4k is needed by the VM, leaving 124k. So the space is 128K, but only 124K is allowed for the app. I suspect the "4k" can changes with CIQ versions, so the 128k number in devices.xml is the base, and then adjusted based on what that specific VM uses. (which if I recall has decreased over time - seems it was close to 6k at one time)
  • Why is my app crashing on the device, with 127,472 bytes of available memory when it apparently has (126,976 - 120,744 =) 6,232 bytes of memory to display a 550 byte png image?

    Are you absolutely certain that the 550b image you are talking about is actually 550 bytes once it is all loaded into memory and converted into the proper format for display? If you create a sample app that will load/unload the bitmap on demand, what is the difference in memory used between when it is loaded and when it is not loaded?
  • Unable to post my reply...JSON error on post! We really do need some work on the Forum!
    See attached screenshot
  • Here's a screenshot of the same test on the Sim.
    Note Peak Memory 106.8Kb = 109,363 bytes.
  • Former Member
    Former Member over 6 years ago
    Travis has hit on an important thing to understand about image resources. The application does not natively work with .PNG files or other formats that are used as the source files for your application. These are compiled into your application as bitmaps native to the devices color depth

    Your attached image is 63x58. Compiled for a wearable (which has 1-byte pixels), this image will be 3654 bytes (+ a bit of overhead). It is a lot less surprising that the application heap might not be able to find 3700 contiguous bytes out of 6232 remaining, than it would be if this was actually 500 bytes on device. You can check the exact size of the image resource by loading it in a test application without unloading it, and finding it in the Memory Viewer.

    This image only uses 4 colors, and could be reduced in size by specifying a color palette of only those 4 colors (plus the disableTransparency flag). This will cut roughly 3/4 of the bitmap data size out, and leave you with an image resource that is probably only about 1KB.

    I have no information about the discrepancy in your runtime size between simulator and device. If possible, you may want to narrow down which point (or points) in your application load these numbers deviate. If you can capture memory usage at distinct checkpoints as your application loads maybe this will single out an operation that is not behaving the same between the two.
  • The application does not natively work with .PNG files or other formats that are used as the source files for your application. These are compiled into your application as bitmaps native to the devices color depth


    Is there a better format to use?

    This image only uses 4 colors, and could be reduced in size by specifying a color palette of only those 4 colors (plus the disableTransparency flag). This will cut roughly 3/4 of the bitmap data size out, and leave you with an image resource that is probably only about 1KB.



    As this was prepared by a 3rd party and my graphic skills are limited, could you provide some pointers here please? How do I specify a color palette, or disable Transparency on a Mac with no fancy drawing package?

    I have no information about the discrepancy in your runtime size between simulator and device. If possible, you may want to narrow down which point (or points) in your application load these numbers deviate. If you can capture memory usage at distinct checkpoints as your application loads maybe this will single out an operation that is not behaving the same between the two.


    Will do and will report back.


  • Former Member
    Former Member over 6 years ago
    It does not matter what format your source image is in. The Connect IQ compiler will convert it to a system native bitmap.

    Nothing needs done to the source image. The palette is specified in the xml where the bitmap is included in your project. There is an example in the programmers guide under Resource Compiler -> Bitmaps.
    The colors in your image are 000000, 555500, AAAA00, FFFF00 and you will need to set disableTransparency to "true" to get the most compression.
  • I suspect I will have to access the source image as I have implemented your suggestion s and I'm now getting
    BUILD: ERROR: Transparency detected in source image 'drawables/notRacingIcon.png' while transparency is disabled.
    on a bunch of icons including this one:

  • This image only uses 4 colors, and could be reduced in size by specifying a color palette of only those 4 colors (plus the disableTransparency flag). This will cut roughly 3/4 of the bitmap data size out, and leave you with an image resource that is probably only about 1KB.

    There's absolutely no clue in the programmer's guide that using a palette will reduce the memory!
  • Former Member
    Former Member over 6 years ago
    I suspect I will have to access the source image as I have implemented your suggestion s and I'm now getting
    BUILD: ERROR: Transparency detected in source image 'drawables/notRacingIcon.png' while transparency is disabled.
    on a bunch of icons including this one:



    The specific guidance on colors and disabling transparency, applied only to the specific image you posted previously. The new one you posted does contain transparency, and as such, cannot be compiled if transparency is disabled. If the image does not require transparency, you could have it edited. For that image, It appears the same palette would work, but without transparency disabled. It will compress less than the previous image since it requires 5 colors, and crosses a bit size threshold (2/4/16 colors)