> When compiling to asm.js/wasm through emscripten or clang you have to take
> special care to not let the GC happen "whenever", but only to let it happen
> when there are no objects referred only from the stack
Isn't it the standard case that objects are only referred to from the stack?
Like when we create a seq/string the data is on the heap, but it is referred to
only from the stack, right?
proc inner() =
for _ in 1 .. 1_000:
# may trigger GC here
let c = newSeq[int](1000)
proc subFunc() =
let b = newSeq[int](1000)
inner()
# does `b` still live?
proc mainEntryPoint() =
let a = newSeq[int](1000)
subFunc()
# does `a` still live?
Run
Let's assume we only call `mainEntryPoint` from JS. Is this the case you mean
-- we are triggering GC from an inner function that is not at the stack bottom,
and the data of `a` and `b` is only referred to from the stack. If I understand
your comment correctly they might get collected, and to prevent them from being
collected I would have to push some references to `a` and `b` to the heap?