duktape: Local functions hold references to local variables they don't use

In the following snippet, the “event” argument and its members will be kept alive for the lifetime of the function assigned to “o.anotherFunction” , although there are no references to the “event” variable

var o = {};
function doSomething(event) {
    o.anotherFunction = function() {}
}

This is problematic, especially in the case of event handling, where the event object may hold object references which will then keep them from being gc’d

I am dubious that there is a standard in this case, though in the case of Lua, upvalues are explicitly marked by the compiler and only promoted to local closures if used.

It took some hours of debugging to figure out why some objects were’t being released as there were no obvious references anywhere to them.

Thanks!

About this issue

  • Original URL
  • State: open
  • Created 9 years ago
  • Comments: 32 (23 by maintainers)

Most upvoted comments

@svaarala Happy New Year! It has been awhile 😃 I am wondering if you have any new thoughts on this issue? It is really easy to leak objects with the behavior.