What to do when 32KB of Glance code isn't enough?

So, I've come to a dead end regarding devices with just 32 KB of Glance (and app) code. When dealing with background code that keep adding until the background data is read, that 32 KB becomes really problematic, especially when just trying to store an array of three element where each element is an array of three numbers with still 10KB of free space up until that setValue call ends up with a Out of Memory error! What?!? I know that arrays of arrays have a small overhead and so does serialization, but common! 10 KB isn't enough?!?

So I tried to not let those devices with just 32KB of Glance have a glance (ie, exclude getGlanceVIew using excludeAnnotations but that ended up with a "A critical error has occurred" (man I hate those, they are often hard to pin point), so that's also a no go.

Is there a way for the Glance code to NOT see the background data altogether? That would solve my problem but I haven't figured out a way to do it. My only other solution is to drop them altogether, which would suck.

Thanks.

  • Redesign without using multi dimensional arrays. There are some topics if I remember correctly describing how they use a lot of memory.

  • Remember when when you see 32kb in the JSON files, CIQ uses 4k of that and it's not available for your app.  You can see this in the sim.

  • That three elements of 3 numbers each takes 130 bytes according to .free memory(). I still had 10 KB left (according to the same call).

  • Yeah, out of the 32 KB, the memory viewer showed I had 27 KB to play with. The highest usage it went to until that Out of memory error was 14 KB.

  • Remember when you do something like an add() to array, while that is happening you actually use double the memory for the array.

    Memory is allocated for the larger array, the original array is copied to the new one, the original array freed and the new element added to the new array.

  • It's really easy to hit that 32KB limit :). Some things that freed up a lot of memory for me (including 15KB from my Background usage):

    1. Don't use <Global>globals variables
      View the Memory window in the Simulator and look at everything under Global globals.  Everything there will have a copy in background instance by default.
    2. Don't use Dictionary
      The Dictionary object uses a lot more space than the raw byte size.  Change to an Array - or even an if-elseif... decision tree.
    3. Make literal "strings" short -- each letter in a string adds about 2 bytes of total overhead, it adds up
    ...
  • 4. Minimize the number of Classes you use -- An empty class declaration adds 300 bytes.  Module declarations have overhead too :/

    5. Minimize the number of Classes with any static declaration in them -- any class with a static inside it adds 60 bytes to <Global> memory

    6.Scope resource/strings only used by settings -- <string scope="settings" ...  -- saved me over 3kB 



    Check out my commit history from Aug16 to Aug19 for concrete examples:

    https://github.com/blueacorn/Infocal/commits/master/?since=2025-08-16&until=2025-08-19