pushing memory limit in simulator

trying to squeeze in yet one more feature for some low memory devices and i'm right on the edge of available memory now (26 out of the theoretical 28.6k).  My code runs fine as long as I leave the simulator in single data field mode.  But as soon as I try to show multiple fields at once, i get out of memory errors.  Although the field still seems to run fine in some of the fields and others are blank. 

I've shipped at least one version like this and I haven't had any complaints nor seeing any errors in the ERA viewer, so I'm hoping it's ok, but does anyone have firm knowledge on this?

  • BACK AWAY FROM THE LIMITS! (Seriously.)

    There are all kinds of ways to reduce memory usage, and almost all of them will earn me a reprimand from Jim for suggesting one might use them as they are all kinda dirty.

    However, there are lots of threads on this if you google.

    Off the top of my head in no particular order:

    1. REFACTOR YOUR CODE! 

    2. Look for any method calls where you only call the method a single time - method definitions use memory - and inline the code

    3. Look for anywhere you could have a method call because you keep repeating lots of identical lines of code. Replace these repeated lines of code with a single method.

    4. Look for long and repeated references like "Class.Object.Bob.Bill" ... each object in the chain introduces a vpush or spush (can't remember which) in the compiled code... which uses up memory. It is often more efficient to start a block with "var bill = Class.Object.Bob.Bill;" and then refer to bill.

    Etc.

    As I say, use the search for this - there are one or two really, really detailed pages long posts with about a gazillion and three ways to cut down from hundreds of bytes down to individual bits.

  • What's kind of odd is that you run out of memory when you change the field layout in the sim.  Have you tried watching "view memory" when you change layouts to see where the memory is going?

    That said, it's something that might be very uncommon on a real device, as I don't think most people use the same DF for multiple fields in the same activity, especially with the 2 CIQ DF limit on many devices.

  • Are you doing something like an add() in your data field and growing an array?  If you do that any place other than compute(), that array could be growing faster than you expect,  If it's being done in onUpdate() and you have a 3 field layout, that will happen 3 times a second vs 1 time a second in compute().

  • That said, it's something that might be very uncommon on a real device

    Whenever I see the message in simulator, I can achieve it on the device. 

    Often, it will work fine once installed but can crash readily when adjusting layouts in activity data screens. 

    Better, I think, to leave a little leeway. (Doesn’t seem to need much, but some is essential.)

  • Scott -In the sim, is the 26k the peak memory (as seen in view memory) or are you going by the bottom line in the sim (which is the idle memory usage)?

    You might be much closer to the max when you think..   And how close you are can impact how much you have to do as far as reducing memory.