Detailed list of RAM usage

Posted on
  • Hi all,

    I'm super excited to receive my Banglejs a few days ago. I've just started to learn JS. I have a quick question. Is it possible to break down the RAM usage by each process (app/widget)? Something like the top command in Linux?

    I'm aware of process.memory(). However, apparently, it is only an aggregation without details at the process (app/widget) level.

    Could anybody hint how to do this?

    Thank you

  • Hi! There's nothing specific, because Bangle.js doesn't enforce enough separation to figure out which code was defined where.

    However there is something called E.getSizeOf(object) which does a recursive scan of JS objects and returns how much data they use.

    For instance E.getSizeOf(WIDGETS,1) will report each widget and how much memory it uses.

    You can also use trace(WIDGETS["gpsrec"]) to dump the full contents of memory starting at that point too.

    Unfortunately the problem is that everything ends up pretty interlinked - specifically when you define a function it references the Global scope (which contains everything) and that makes separating everything pretty painful. I've just made some changes so E.getSizeOf in the absolute latest firmware doesn't follow links back to the global scope, and that should give you a much better set of figures

  • Sounds like a good idea with the E.getSizeOf. I'm still reading manuals and learning. Let me see what I can do with it.

    When you say "things are interlinked" and "separating everything is painful", do you mean that the memory used by a widget might not be continuous? So that it is hard to follow all links/pointers internally?

    Thank you

  • The memory used isn't continuous, but that's by design and not too much of an issue.

    It's more that with JS you have this idea of an execution scope. So take this example:

    function a() {
      var b = 42;
      return function() { return b; };
    }
    getB = a();
    getB(); // returns 42
    

    The getB function isn't just function() { return b; } - it contains a pointer to the 'execution scope' of a so it can access the value of b.

    So in this case, E.getSizeOf(getB) returns a value much bigger than E.getSizeOf(function() { return b; }). It makes some sense here, but when you get to bigger projects, it can make it difficult to find out where your memory is actually being used.

  • This is interesting. Honestly, I just started JS so I really appreciate your clear explanation. I will try to read more about JS and let's see what I can do. Thank you.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Detailed list of RAM usage

Posted by Avatar for Weiming @Weiming

Actions