josephg / node-foundationdb

Modern Node.js FoundationDB bindings
Other
115 stars 17 forks source link

Fix memory leaks in watch and callback API-s #83

Closed keijokapp closed 2 months ago

keijokapp commented 2 months ago

Resolves #82

Apparently, the references created in watchFuture and fdbFutureToCallback have to be deleted explicitly in addition to being unref-ed. Just deleting wouldn't be enough either. After applying this patch, the memory usage seems to eventually flatline and Valgrind is reasonably happy.

From Node-API doc:

References must be deleted once they are no longer required by the addon. When a reference is deleted, it will no longer prevent the corresponding object from being collected. Failure to delete a persistent reference results in a 'memory leak' with both the native memory for the persistent reference and the corresponding object on the heap being retained forever.

josephg commented 2 months ago

Good catch! Thanks for figuring this out.