Skip to content

Commit 8988fe4

Browse files
fix: deref garbage collected owned refs (#41)
1 parent fd4658b commit 8988fe4

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/python.ts

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import { py } from "./ffi.ts";
44
import { cstr, SliceItemRegExp } from "./util.ts";
55

6+
const refregistry = new FinalizationRegistry(py.Py_DecRef);
7+
68
/**
79
* Symbol used on proxied Python objects to point to the original PyObject object.
810
* Can be used to implement PythonProxy and create your own proxies.
@@ -202,6 +204,7 @@ export class PyObject {
202204
*/
203205
get owned(): PyObject {
204206
py.Py_IncRef(this.handle);
207+
refregistry.register(this, this.handle);
205208
return this;
206209
}
207210

0 commit comments

Comments
 (0)