Skip to content

Commit

Permalink
fix: deref garbage collected owned refs (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
eliassjogreen authored Jul 22, 2023
1 parent fd4658b commit 8988fe4
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -202,6 +204,7 @@ export class PyObject {
*/
get owned(): PyObject {
py.Py_IncRef(this.handle);
refregistry.register(this, this.handle);
return this;
}

Expand Down

0 comments on commit 8988fe4

Please sign in to comment.