Destructors
Destructors copied to clipboard
Readme.md is outdated; example DtorType.Function causes leak
Sample code uses dtor_track instead of dtor; anonymous function variable somehow causes the weak reference to stay alive ("Destructed!" is never printed).
function foo1() constructor {
dtor(DtorType.Function, function () {
show_debug_message("Destructed 1!");
});
}
var a1 = new foo1();
delete a1;
function foo2() constructor {
func = function () {
show_debug_message("Destructed 2!");
};
dtor(DtorType.Function, func);
}
var a2 = new foo2();
delete a2;
function foo3() constructor {
function func() {
show_debug_message("Destructed 3!");
};
dtor(DtorType.Function, func);
}
var a3 = new foo3();
delete a3;
Weirdly only a3 works.
Hi thanks for reporting the error. try replacing the DtorInstance code with the following code
/// @ignore
/// @param {enum.DtorType} type
/// @param {Any} value
/// @param {Any} [options]
/// @param {Any} [reference]
function DtorInstance(_type, _value, _option, _ref) constructor {
static use = {}; // Bound Methods to this struct
reference = weak_ref_create(_ref);
type = _type;
// Not bound
value = (is_method(_value) ) ? method(use, _value) : _value;
option = _option;
}
Thanks for the fix!