Skip to content

Commit cd51a38

Browse files
committed
Remove attach_destroy_finalizer
1 parent 08674cf commit cd51a38

File tree

1 file changed

+0
-30
lines changed

1 file changed

+0
-30
lines changed

pyadjoint/optimization/tao_solver.py

-30
Original file line numberDiff line numberDiff line change
@@ -25,31 +25,6 @@
2525
]
2626

2727

28-
def attach_destroy_finalizer(obj, *args):
29-
"""Attach a finalizer to `obj` which calls the `destroy` method on each
30-
element of `args`. Used to avoid potential memory leaks when PETSc objects
31-
reference themselves via Python callbacks.
32-
33-
Note: May lead to deadlocks if `obj` is destroyed asynchronously on
34-
different processes, e.g. due to garbage collection.
35-
36-
Args:
37-
obj (object): A finalizer is attached to this object.
38-
args (Sequence[object]): The `destroy` method of each element is
39-
called when `obj` is destroyed (except at exit). Any `None`
40-
elements are ignored.
41-
"""
42-
43-
def finalize_callback(*args):
44-
for arg in args:
45-
if arg is not None:
46-
arg.destroy()
47-
48-
finalize = weakref.finalize(obj, finalize_callback,
49-
*args)
50-
finalize.atexit = False
51-
52-
5328
class PETScVecInterface:
5429
"""Interface for conversion between :class:`OverloadedType` objects and
5530
:class:`petsc4py.PETSc.Vec` objects.
@@ -82,8 +57,6 @@ def __init__(self, x, *, comm=None):
8257
self._N = N
8358
self._isets = isets
8459

85-
attach_destroy_finalizer(self, *self._isets)
86-
8760
@property
8861
def comm(self):
8962
"""Communicator.
@@ -641,9 +614,6 @@ def apply(self, pc, x, y):
641614
self._tao = tao
642615
self._x = x
643616

644-
attach_destroy_finalizer(
645-
self, tao, H_matrix, M_inv_matrix, B_0_matrix_pc, B_0_matrix, x)
646-
647617
@property
648618
def tao_objective(self):
649619
"""The :class:`.TAOObjective` used for the optimization.

0 commit comments

Comments
 (0)