Skip to content

Commit efcf5c4

Browse files
Add GC limitation note in README.md
1 parent 6c605ba commit efcf5c4

File tree

1 file changed

+28
-0
lines changed
  • packages/npm-packages/ruby-head-wasm-wasi

1 file changed

+28
-0
lines changed

packages/npm-packages/ruby-head-wasm-wasi/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,34 @@ See [the example project](https://github.com/ruby/ruby.wasm/tree/main/packages/n
8585
</html>
8686
```
8787

88+
89+
## GC limitation with JavaScript interoperability
90+
91+
Since JavaScript's GC system and Ruby's GC system are separated and not cooperative, they cannot collect cyclic references between JavaScript and Ruby objects.
92+
93+
The following code will cause a memory leak:
94+
95+
```javascript
96+
class JNode {
97+
setRNode(rnode) {
98+
this.rnode = rnode;
99+
}
100+
}
101+
jnode = new JNode();
102+
103+
rnode = vm.eval(`
104+
class RNode
105+
def set_jnode(jnode)
106+
@jnode = jnode
107+
end
108+
end
109+
RNode.new
110+
`)
111+
112+
rnode.call("set_jnode", vm.wrap(jnode))
113+
jnode.setRNode(rnode);
114+
```
115+
88116
<!-- The APIs section was generated by `npx documentation readme ./dist/index.esm.js --section=APIs` -->
89117

90118
## APIs

0 commit comments

Comments
 (0)