cmake-js/fastcall

Possible memory leak when using Disposable

tomkha opened this issue · 1 comments

I use lots of disposable objects in my app, objects are created and then disposed by garbage collector, dispose function is called perfectly. Still I noticed that the memory usage grows constantly.

Here is the simplified version of the application.

const fastcall = require('fastcall');
const Disposable = fastcall.Disposable;

let objCount = 0;

class SomethingDisposable extends Disposable {
    constructor(releaseFunction) {
        super(releaseFunction);
        objCount++;
    }
}

function releaseSomething() {
    objCount--;
}

function createSomething() {
    return new SomethingDisposable(releaseSomething);
}

function createObjects() {
    createSomething();
    console.log(`Objects count = ${objCount}`);
    if (objCount % 10000 === 0) {
        if (global.gc) {
            global.gc();
        }
    }
    if (objCount < 50000) {
        setImmediate(createObjects);
    }
}

createObjects();

I ran it with GC exposed : nodejs --expose-gc index.js so it never keeps more than 10k objects in memory effectively running in the infinite loop creating and releasing those objects. Nevertheless the memory used by NodeJS increases pretty fast and it is never released.

It looks like this happens because WatchStuff.callback member (src/weak.cpp) is never released (though I might be mistaken).

P.S. Disposable objects in my app are Nooocl's clEvent.

Fixed as of 0.2.5. Ty for the PR and sry for the delay.