getting Error: Out Of Memory Error Details: Failed invoking

Hi, I was trying to make a watch face with settings and was able to make it due to a lot of help here. I have another problem right now, when I am trying to run the code on every watch besides vivoactive 4 or Venu 2 I see the following error:

Error: Out Of Memory Error
Details: Failed invoking <symbol>
Stack: 
  - onUpdate() at C:\temp\eclipse-workspace
arutoWithSettings\source\watchimageView.mc:71 0x10000282 

I have the watch built right and just like I wanted but with an IQ icon on it like in the following image: 

I ran the simulator and check the view memory and this is what I got:

the memory usage isn't so close to max memory and there's also no problem with the peak memory so I am clueless about what causing the problem. Can you help me?

TY in advance!

  • BTW tried to refresh anything and load the connect iq add on again. Got the same result

  • Are you using the exact same target in the sim as the device where you get the IQ!?  Is there anything else involved, like you are using app settings on the real device?  That will cause a spike in peak in many cases.

  • Hi jim, I didn't understand your question. What do you mean as 'the device where you get IQ'. I am running the code in ecllipse and that"s what i got in the simulator. Isn't it supposed to be a peak in the simulator if it uses app settings in the device himself?

  • Ok, so the out of memory you see is in the sim.  Is it only just one device? When you change someithing with app settings, it takes more memory.  In simple terms it needs the old settings in addition to the new settings so they  can be merged.

  • I hope I understood now. I set the watch face in the manifest file to fit every watch face that has the pixel size of 240×240, 260x260 and 416x416 and round devices only. I did it by manually downloading the devices 1 by 1 in the sdk manager after checking every device in the reference guide. All of the watches besides venu 2 and vivoactive 4 looks just like the picture I added to the post. I used the old settings and merged them with the settings file after I created the watch face with settings via the new project file of the connect IQ. Also I generated a new UUID via manifest.xml, dont knoe if it has anything with the situation.

  • Update: tried to check if memory is the real problem by removing all of the resource files of 260x260 and 416x416 pixels. What I got was this result in sim memory:

    The memory usage and peak changed by almost nothing, yet the watch face simulator shows the exact same result. It drives me crazy because The error showed makes no sense to me and there are so much more complicated watch faces that works with those devices.

  • The original error message you posted showed a crash on line 71 of watchimageView.mc,

    Error: Out Of Memory Error
    Details: Failed invoking <symbol>
    Stack:
      - onUpdate() at C:\temp\eclipse-workspace
    arutoWithSettings\source\watchimageView.mc:71 0x10000282

    Have you changed the code since then? Is it crashing in the same place? What does the code look like on and around the line that crashes?

  • Hi ty for the answer, here's the whole view code: https://pastebin.com/xL4GLCzW.

    the error in line 71 is the If condition for the settings. This is the main difference here because on the simple watch face I managed to customize it for all of the 240x240 , 260x260 and 416x416 pixels size devices without any problem.

  • Here's lines 70-75 of the code (in your view's onUpdate()):

    var W = Application.Properties.getValue("BackgroundColor");    
    if (W==0) {BG=WatchUi.loadResource(Rez.Drawables.WhiteBG);} // <==== crash is here
    if (W==1) {BG=WatchUi.loadResource(Rez.Drawables.DarkOrangeBG);}
    if (W==2) {BG=WatchUi.loadResource(Rez.Drawables.LightOrangeBG);}
     

    dc.drawBitmap(0, 0, BG);

    Not to state the obvious, but you're running out of memory when you load the resource.

    If you want to see the effect of this on peak memory, you could create a minimal test app that does nothing but load this resource (for one of devices that currently crashes) and:

    1) Run it normally and look at peak memory

    2) Run it with loadResource() commented out and look at peak memory

    The difference in peak memory should be the memory spike associated with loading the resource (assuming your test app isn't doing anything else that uses a lot of memory)

    In any case, I don't think it's recommended to load a resource in onUpdate for a few reasons:

    - it could be CPU-intensive / slow

    - it could be memory-intensive (as you've seen)

    - it's not necessary (in this case) to reload the same resource over and over again for a setting that will rarely change

    Regardless of what you find about the memory impact, it would be probably best to:

    - Load the resource once in your view's initialize() code and save the value of the app setting "BackgroundColor"

    - Override onSettingsChanged in the app class (https://developer.garmin.com/connect-iq/api-docs/Toybox/Application/AppBase.html#onSettingsChanged-instance_function) and check to see if BackgroundColor has changed. If so, load the new bitmap here.

  • Also, it seems to me you're showing the peak memory for VA4 or Venu 2 in your screenshots, since they're not crashing and other watches are.

    It might help if you looked at the peak memory for a device that actually does crash. If you want to see the peak memory without loadResource, try running your existing code withLoadResource()) commented out, for one of the devices which is crashing.

    Peak Memory + Memory Spike (as found based on the other suggestion) should be more than the total available memory, for that device.