Closed
Description
import { setTimeout } from "os";
import { gc } from "std";
const g = {
a: null,
b: null
};
function fun1() {
var obj1 = {
timeout: null,
ref: null
};
obj1.timeout = setTimeout(function() {
console.log("ok!");
}, 3000);
var obj2 = {
str: "123",
ref: null
};
g.a = obj1;
g.b = obj2;
}
function fun2() {
g.a.ref = g.b;
g.b.ref = g.a;
g.a = null;
g.b = null;
}
fun1();
fun2();
gc();
Running the above code will crash。
I debugged the source code and found that obj1 and obj2 have circular references to each other, and obj1 also references a callback. When gc() is called, obj1, obj2, and the referenced callback object are released. However, when the timer times out and tries to call the callback of obj1, it crashes.
Metadata
Metadata
Assignees
Labels
No labels