Tips on saving memory?

I am building a very resource intensive ballistic calculation application. On startup (after the initial calculations) the memory consumption is at 50k. The calculations are so heavy I need to divide them into slots and use a Timer and ProgressBar to do them in small parts not to trigger the Watchdog timeout. Since the current implementation of BrogressBar is leaking memory, each re-calculation of the output values increases the memory consumption by 3k. So to keep on developing with the emulator, I need to figure ways to free some memory.

Any "insider" tips on how to be memory-effective? I've already converted all the doubles I can to floats and draw all graphics "by hand" instead of using bitmaps.

Also, regarding the memory usage, is it better to use the layout system, or just draw everything in the code?
  • Since the current implementation of BrogressBar is leaking memory, each re-calculation of the output values increases the memory consumption by 3k. So to keep on developing with the emulator, I need to figure ways to free some memory.

    I think my first tip would be to stop using the progress bar for the time being. If it is leaking memory, no amount of optimization can undo that. It might not be ideal, but you could implement something that has the same API as the ProgressBar and use that as a placeholder for now.

    Any "insider" tips on how to be memory-effective? I've already converted all the doubles I can to floats and draw all graphics "by hand" instead of using bitmaps.

    I think that is a good start. I think organizing your data to minimize use of arrays and maps is helpful. e.g., instead of storing an array of N arrays each with 2 elements, store one array with 2*N elements and stride over them. You can look into bit backing your data, but there are trade-offs with that.

    Also, regarding the memory usage, is it better to use the layout system, or just draw everything in the code?

    Interesting that you ask. I'm currently working on a project that is running up to the memory limit. I found that on the simulator I'm seeing about 5K more memory being used after switching over to layouts. After loading the initial view and nothing else, the initial implementation shows 14180b free, and the layout version uses 9395b.

    I have noticed that if I switch views a few times a bunch of memory becomes available (9395b jumps up to 13296b). I'm going to spend some time this weekend verifying what I'm seeing in the simulator is consistent with what happens on the device, and trying to find ways to try to cut down on memory usage to bring things back closer to being in line.
  • Former Member
    Former Member over 10 years ago
    Layouts will generate some code procedurally, which is probably going to be a bit less efficient than writing it out as long as you are careful.

    While it is of no help to you right now, we do have a fix for the excessive memory usage of longs and doubles coming in a future release. (They will still obviously be a bit larger than ints/floats)

    Using a placeholder class for the progress bar to work around the current leak as Travis suggested is a good idea.

    Make sure you don't have dead code floating around in your source. ConnectIQ can't do any link time optimization to remove unused functions, and all of your code is loaded into your available memory when your app is active.