From 8988fe4c6019213d522d8e80ff5be0caf37b6b1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20Sj=C3=B6green?= Date: Sat, 22 Jul 2023 23:17:14 +0200 Subject: [PATCH] fix: deref garbage collected owned refs (#41) --- src/python.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/python.ts b/src/python.ts index 77c67f2..7ea7883 100644 --- a/src/python.ts +++ b/src/python.ts @@ -3,6 +3,8 @@ import { py } from "./ffi.ts"; import { cstr, SliceItemRegExp } from "./util.ts"; +const refregistry = new FinalizationRegistry(py.Py_DecRef); + /** * Symbol used on proxied Python objects to point to the original PyObject object. * Can be used to implement PythonProxy and create your own proxies. @@ -202,6 +204,7 @@ export class PyObject { */ get owned(): PyObject { py.Py_IncRef(this.handle); + refregistry.register(this, this.handle); return this; }