arqex / freezer

A tree data structure that emits events on updates, even if the modification is triggered by one of the leaves, making it easier to think in a reactive way.
MIT License
1.28k stars 56 forks source link

JavaScript heap out of memory when using freezer-js #113

Closed senthil5053 closed 5 years ago

senthil5053 commented 6 years ago

I bump in heap out of memory issue after a run-time of my NodeJS application for about 30 mins. Below is the snippet of code i use:

var  map = new Map({});
var freezer = new Freezer({starttime: startime});
var state = freezer.get();
map.set(messageid, state);
    freezer.on('update', function (newValue) {
        var result = freezer.get().result;
        callback(result);
        map.delete(messageid)
    });

// then on my onMessage() 
 var state = map.get(jsonObj.messageid);
 if(state)         
      state.set('result', jsonObj.response);
 /* anonymous */ [....js:~104] [pc=0x3c4c14a55a32](this=0x24fc8b90beb1 <JSGlobal Object>,newValue=0xc5538810209 <Object map = 0x394a8770b0a9>)
    4: trigger [/deploy/node_modules/freezer-js/src/emitter.js:56] [bytecode=0xedfaac44a49 offset=100](this=0x1c8334054bf9 <Freezer map = 0x373ac0598049>,e...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

2018-05-22 17:10:12,483 DEBG 'node-app' stdout output:
 1: 
2018-05-22 17:10:12,483 DEBG 'node-app' stdout output:
node::Abort() [node]
 2: 
2018-05-22 17:10:12,483 DEBG 'node-app' stdout output:
0x121a2cc [node]
 3: 
2018-05-22 17:10:12,488 DEBG 'node-app' stdout output:
v8::Utils::ReportOOMFailure(char const*, bool) [node]
 4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [node]
 5: v8::internal::Factory::NewRawTwoByteString(int, v8::internal::PretenureFlag) [node]
 6: v8::internal::String::SlowFlatten(v8::internal::Handle<v8::internal::ConsString>, v8::internal::PretenureFlag) [node]
 7: v8::internal::Factory::NewProperSubString(v8::internal::Handle<v8::internal::String>, int, int) [node]
 8: v8::internal::Runtime_SubString(int, v8::internal::Object**, v8::internal::Isolate*) [node]
 9: 0x3c4c13f0463d

@arqex Am I missing anything to handle this kind of memory leak ? How can I gracefully handle this ? Could you please help me here

arqex commented 6 years ago

Hey @senthil5053 What's that callback function doing? It's really weird to have a memory leak inside emit, it might be produced by whatever function is inside of the update handler, and the only one I see could be problematic is callback

arqex commented 5 years ago

No activity on this thread for long time, closing