Out of memory error

Former Member
Former Member
Hi,

I don't understand the managing of the memory ...
I add errors when putting some System.println , and when removing, I don't have them again.
Unfortunately, this didn't work all the time. I need then to understand it ...
I have memory error, often on this code :

fmt = "" + hours + "h" + minutes.format("%02d");


I try to read this topic https://forums.garmin.com/archive/index.php/t-319811.html or https://forums.garmin.com/archive/index.php/t-214247.html, but it didn't help me, I still don't understand how to manage it.

Thanks
  • Try hours.toString() when you build a string.
    Maybe the type of hours is a number or something that does not get cast implicitly.
  • When you run in the simulator, what does it say memory is on the bottom line? With the 2.1.x SDK, you'll see current/max, and peak.

    If peak is getting close to max, adding a few Sys.println() calls can give you an out of memory error.
  • Former Member
    Former Member over 8 years ago
    Try hours.toString()

    This didn't work :(

    When you run in the simulator, what does it say memory is on the bottom line?

    Where ? I run in the simulator, but it says nothing :

    [HTML]
    File pushed successfully
    Connection Finished
    Closing shell and port
    Found Transport: tcp
    Connecting...
    Connecting to device...
    Device Version 0.1.0
    Device id 1 name "A garmin device"
    Shell Version 0.1.0
    onTimerStart
    Failed invoking <symbol>
    Out Of Memory Error
    in fmtTime (/Users/admin/Documents/eclipse/workspace/COCProj/source/COCFields.mc:362)
    in compute (/Users/admin/Documents/eclipse/workspace/COCProj/source/COCFields.mc:583)
    in compute (/Users/admin/Documents/eclipse/workspace/COCProj/source/COCFieldsView.mc:197)
    Connection Finished
    Closing shell and port
    [/HTML]

    With the 2.1.x SDK, you'll see current/max, and peak.

    where ?

    If peak is getting close to max, adding a few Sys.println() calls can give you an out of memory error.


    I remove all, and I still have them.

    I add some
    System.println("before return "+System.getSystemStats().usedMemory);
    to see my memory, but it didn't talk to me ...

    Do we have a way to manage it ? Free some objects ? I try to put myArray = null; sometimes, but it didn't change neither.

    but this didn't change
  • When you run the simulator, the bottom line in the simulator window shows the memory usage of your app.

    What are the numbers you see there?
  • This didn't work :(


    Yeah sorry, I misunderstood your post. From Jim's reply to your post I concluded that the println gives you out of memory, not that there is a specific error about wrong type by the println statement that you posted.
  • Here's where you can watch the memory and see what's happening:




    Or do you get the "out of memory" before your app even starts? In that case, comment out some code until it can start.
  • Former Member
    Former Member over 8 years ago
    OK thanks for the tip of the memory on the simulator.
    I think I found the issue, even I don't understand why ...

    In fact I change my code to use the settings instead of hard coding the values, and if I launched my app with the defaults values (in the .properties file) I had memory errors; but when I sent new settings through App settings editor, the issue didn't appears again ...

    But this remains not clear to me, there is no way to manage the memory. As I understood in the programmer's guide, there is an equivalent of garbage collector (reference counting) that manage it.
  • Former Member
    Former Member over 8 years ago
    Playing with the code I found out that although there is a garbage collector indeed since memory is actually freed after around a couple of seconds, but sometimes it's not fast enough, especially if you wait for memory-hungry structures like dictionaries to release their memory. But there is a trick: if you use statements like "<structure>= null" explicitly, then memory is cleared almost instantly. E.g. if you have some temporary dictionaries or arrays, then do not forget to assign them to null to make sure memory is released right away. At least that's how it works in simulator.
  • Former Member
    Former Member over 8 years ago
    OK,
    thanks, I try this, but it didn't solve my issue.
    I found it very weird, because my "trick" when sending new properties through "App Settings Editor" didn't work anymore . But if I build my app and put it in my watch, this work.
    Now, in the simulator the app crash in the launching.
    This is not possible to increase the 16kb of the simulator ?
    Because, this is painful those kind of error without a lot of informations for debuggind ...
  • Different devices have different attributes. The amount of memory that is reserved for ConnectIQ is not something you can change; you just have to write code with it in mind.

    Travis