Code Overlays

Former Member
Former Member
I have hit the dreaded 'out of memory error'. My app takes 57K even just showing the initial menu. The app has a very small amount of global data so most of this 57K is code.

The structure of the app, like many I suspect, is a hierarchical series of menus that configure the global data to be used when the activity (sailing in my case) starts. Many of the menus cover optional items so may not be invoked at all, or maybe just once when configuring how the activity is gong to run. All the menus and associated code form part of the memory footprint, as would be expected.

My understanding of resources is they are not part of the apps memory footprint until they are loaded and the memory is recovered when they go out of scope or are explicitly freed by setting the resource reference to null. If code could be stored as a resource and loaded, run and freed under program control then this would be one way to extend the app without exceeding its memory footprint. Code overlays are not a new idea and would obviously need some restriction on how they interact with the system (only one level of overlays) and the rest on the app (just access global data).

If the amount of memory an app is allocated is based on some arbitrary decision and not fixed by some hardware limit then the best solution is to increase it :-) but failing that code overlays provide a solution.

I am not expecting an app's memory size to be increased or code overlays implemented anytime soon, but just mentioning them as possible future options.

I will need to spend some time looking at the assembler output and debug information to understand where the space is going to direct some optimisation work. I am sure I can make some improvements, but even so it is disappointing to have to drop some planned features.

Dave.
  • The memory part is kind of being addressed with 2.1 device. Apps there can be 122k. I doubt you'll see any change from 64k on 1.2/1.3 devices

    As far as your case, is the 57k peak memory? How about idle memory and what's thedifferent in amounts? (both are shown on the bottom line of the sim).

    Can you move at least some of the menu things into app settings (GCM/GE)

    I know in the case of just a simple (standard) menu, it uses about 1.5 just to display it.

    What watch are you using? I noticed the other day f3 and f3-hr device, doing .fit recording grabs about 7k out of the 64k (not the case on 2.1 devices, the forerunners, or va-hr)

    If you look in devices.xml for the f3, you'll see this:

    <app id="watch-app" memory_limit="65536" fit_session_memory="7168" />
  • Former Member
    Former Member over 8 years ago
    I am on a fenix3. The 57K is idle memory and it peaks at 63.9K. Scarily close to a crash!

    Unfortunately most of the settings need to be adjusted 'on the water'. The few can avoid that and I may have to go down the route you suggest, but I don't think it is going to be big savings.

    I already tried to do FIT recording and ran out of memory immediately. This is one of the planned features I have had to drop.

    It is good to hear 2.1 devices will have more memory, but making use of that will cut you off from all the existing watches so I think a backward looking solution still seams a good idea.

    I was quite surprised as to how quickly memory is used up by code - what I have written doesn't seem it should take as much space as it does.

    Dave.
  • With app settings and GCM, you can make changes "on the water" while your app is running ( onSettingschanged() allows an app to know the properties need to be reloaded in your app). You just need your phone.

    57k without recording when idle strikes me as quite high. My latest app (with recording) has a peak of just over 48k and an idle of about 46k (more on an f3, as I indicated above). I have a handfull of classes, and don't use layouts, but i do save the lat/lon every minute (for up to 12 hours) so that's a chunk of memory right there in my app (without the data arrays, I'd be under 40k)

    How much data do you save and how do you save it? You might get some space there. There also might be some code you can re-write, etc, or some basic restructuring of the code (fewer classes?).