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!

  • Hi ty for your advise, I think that it might be because I used it on the onUpdate, I will check and let you know in a few minutes! BTW I showed the peak memory for forerunner 645 that did crushed but that was still what I got in the view memory for the code which was super weird

    EDIT: TY  it solved the situation! as a guy who is new to programming and especially for connect iq I didn't know that the  onUpdate is memory-intensive and CPU-intensive while loading resources so it is also very informative!

  • Yes.  The va4 has 507K for a watch face, as does the venu.  The venu2 maxes at 92K, but there is a HUGE difference with the venu2 - it's a CIQ 4.x device and has a graphics pool. so things like bit maps and custom font are not in the applications memory.

    These devices are really an exception to other CIQ devices,  Most have far less memory for watchfaces, and don't have a graphics pool.

  • Np. You're welcome!

    I meant that loadResource() itself is memory- and CPU-intensive, so you should try not to call it too often.

    It also does make sense that memory usage would be lower during initialize() as opposed to onUpdate(), as other things might be happening during a screen update. Also, in your original code, since you loaded a background resource for every call of onUpdate() and saved it in a class variable, you were likely using up twice the memory necessary to store one BG image, at peak.

    Consider this code:

    if (W==0) {BG=WatchUi.loadResource(Rez.Drawables.WhiteBG);} // <==== crash is here

    To keep things simple, let's assume W is always 0.

    Let's say your memory usage before calling loadResource for the first time is X. Let's say the memory used by loadResource is Y, and the memory taken up BG (after loadResource is done) is Z. It's reasonable to assume that Y is greater or equal to Z, since loadResource has to load the resource and translate it into a result to be assigned to BG.

    - Before you call loadResource, your memory usage is X.

    - The first time you call loadResource, memory spikes to X + Y, then settles down to X + Z once loadResource returns

    - The 2nd time you call loadResource, your memory usage is X + Z. During the call to loadResource, memory spikes to X + Y + Z, before settling down to X + Z once again

    - Since we assume that Y is >= to Z, your peak memory is at least X + 2Z, which might help explain your crash

    - Aside from taking loadResource out of onUpdate(), it seems that if you're going to store BG in a class variable, and if you're going to load it one more than once (e.g. in onSettings()), you can still save memory by setting BG to null before loading the resource. (I'm assuming that the compiler doesn't do this implicitly before the call to loadResource)

    So if you're going to override onSettings() as I suggested, then you should test pushing new settings to the watchface while it's running. If that still causes a crash, then you'll have to try to save memory in other ways, like setting BG to null before calling loadResource().