pyamgx icon indicating copy to clipboard operation
pyamgx copied to clipboard

Use weak references to automate object cleanup

Open shwina opened this issue 5 years ago • 1 comments

Currently, all pyamgx objects must be explicitly cleaned up by calling a .destroy() method, but it should be possible to automatically clean up objects when they go out of scope (or at exit), using weakref.finalize - Python >= 3.4 only.

shwina avatar Oct 15 '19 13:10 shwina

Work on this has been started at https://github.com/shwina/pyamgx/tree/0.2dev. We don't really need to use weakref.finalize -- Cython's __dealloc__ works fine to automate cleanup. We just need to be careful to keep references to upstream objects: for example, each Vector should keep a reference to the Resources object it depends on.

shwina avatar Jul 30 '20 12:07 shwina