Context in v0.19.4 causes crash after a couple of refreshes? maybe?


Hi All,

Just found a bad one.
I have a flow which puts some data in global.
This data contains references to BLE noble devices, which are HUGE trees with circular references.
I just refreshed my RPi, and put on the latest NR (0.19.4 at the time) - normally i'm using 0.17.x
What I find is that every browser refresh, NR uses an additional 30MB of RAM; which on the constrained RPi, causes death after 2-3 refreshes.
When I looked for new features which could be causing this, I find a new cool feature 'context' on the webpage. This seems to only be populated on refresh.
In my case, I think the volume of data is excessive for the RPi, and also does not seem to be being disposed of....
I could think of a few workarounds (e.g. creating a function which contains the data and access methods to get it, so hiding it from the front end), but has anyone else had a problem with this?
Is the non-releasing of data (i.e. the increase by 30Mbytes on a refresh) a bug?




That sounds ominous! You really need to post your flow, if possible.


I've just reworked it to put a function into global rather than the data, and it does resolve the massive memory leakage.

I tried a different large structure (an object with circular refs, 200 deep, with an array of 200 at each level), and although it uses memory, it does not seem to leak.
I'm thinking now that the duplication of the original noble devices structure was just SO vast, that it caused some allocation failures in the process, which is where the leakage came from.

so; for anyone else who may have a similar issue:
1/ don't put big structures in global.
2/ big structures CAN be represented in global using something like:
(a closure?)

var fn = global.get('fn');

if (!fn){
    f = function() {
        var data = myBigData;
        var getdata = function() {
            return data;  
        return getdata;
    fn = f();
    global.set('fn', fn);
    node.warn("new global fn");
} else {
    node.warn("existing global fn");

var myBigData = fn();

// use big data from global....

a/ Is there a way to turn the context display functionality off?
b/ maybe there should be a way of telling NR that it's to hide specific context from the front end (maybe _ prefix, or something simple).

I do put a lot of info into context, in global, flow, and node context. This is going to hit me over and over with the existing flows I have :(.




original flow is here:

but it may not break if you don't have BLE devices, and is dependent on this:

and BLE on RPi; and require in global..
So it may not be easy to reproduce....