|
25 | 25 | ]
|
26 | 26 |
|
27 | 27 |
|
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 |
| - |
53 | 28 | class PETScVecInterface:
|
54 | 29 | """Interface for conversion between :class:`OverloadedType` objects and
|
55 | 30 | :class:`petsc4py.PETSc.Vec` objects.
|
@@ -82,8 +57,6 @@ def __init__(self, x, *, comm=None):
|
82 | 57 | self._N = N
|
83 | 58 | self._isets = isets
|
84 | 59 |
|
85 |
| - attach_destroy_finalizer(self, *self._isets) |
86 |
| - |
87 | 60 | @property
|
88 | 61 | def comm(self):
|
89 | 62 | """Communicator.
|
@@ -641,9 +614,6 @@ def apply(self, pc, x, y):
|
641 | 614 | self._tao = tao
|
642 | 615 | self._x = x
|
643 | 616 |
|
644 |
| - attach_destroy_finalizer( |
645 |
| - self, tao, H_matrix, M_inv_matrix, B_0_matrix_pc, B_0_matrix, x) |
646 |
| - |
647 | 617 | @property
|
648 | 618 | def tao_objective(self):
|
649 | 619 | """The :class:`.TAOObjective` used for the optimization.
|
|
0 commit comments