emscripten-core/emscripten

Use WeakRefs in event handlers?

Open

#9,820 建立於 2019年11月11日

在 GitHub 查看
 (3 留言) (0 反應) (0 負責人)C++ (3,519 fork)batch import
good first bughelp wanted

倉庫指標

Star
 (27,361 star)
PR 合併指標
 (平均合併 19天 10小時) (30 天內合併 147 個 PR)

描述

See e.g. https://github.com/emscripten-core/emscripten/issues/5456#issuecomment-552005331 and other reports in the past. If one creates event handlers then the module cannot be GC'd even if nothing but the event handlers refers to it. The handlers must be unregistered manually.

If all event handlers used a WeakRef to everything else, then the module can be gc'd, and then the event handler can see it can just exit (and unregister itself).

As WeakRefs are not supported everywhere yet, we'd need to check for their presence.

I'm not sure if this would need to be an option or not. Doing it automatically would help some things, but maybe some codebases do want to stay alive due to event handlers.

貢獻者指南