diff --git a/ppafm/HighLevel.py b/ppafm/HighLevel.py index 508bee2..f150bd8 100755 --- a/ppafm/HighLevel.py +++ b/ppafm/HighLevel.py @@ -1,7 +1,6 @@ #!/usr/bin/python import sys -import weakref import numpy as np @@ -211,11 +210,9 @@ def prepareArrays(FF, Vpot, parameters): gridN = np.shape(FF) parameters.gridN = gridN core.setFF_Fpointer(FF) - weakref.finalize(FF, core.deleteFF_Fpointer) # Set array pointer to NULL when garbage collector runs. if Vpot: V = np.zeros((gridN[2], gridN[1], gridN[0])) core.setFF_Epointer(V) - weakref.finalize(V, core.deleteFF_Epointer) else: V = None return FF, V @@ -462,5 +459,3 @@ def subtractCoreDensities( print("sum(RHO), Nelec: ", rho.sum(), rho.sum() * dV) # check sum if bSaveDebugDens: io.saveXSF("rho_subCoreChg.xsf", rho, lvec, head=head) - - core.deleteFF_Epointer() diff --git a/ppafm/core.py b/ppafm/core.py index a427cbe..b84276b 100755 --- a/ppafm/core.py +++ b/ppafm/core.py @@ -1,5 +1,6 @@ #!/usr/bin/python +import weakref from ctypes import POINTER, Structure, c_double, c_int import numpy as np @@ -76,6 +77,7 @@ def setFF_shape(n_, cell, parameters=None): def setFF_Fpointer(gridF): lib.setFF_Fpointer(gridF) + weakref.finalize(gridF, deleteFF_Fpointer) # Set array pointer to NULL when garbage collector runs. # void setFF_pointer( double * gridF, double * gridE ) @@ -85,6 +87,7 @@ def setFF_Fpointer(gridF): def setFF_Epointer(gridE): lib.setFF_Epointer(gridE) + weakref.finalize(gridE, deleteFF_Epointer) # Set array pointer to NULL when garbage collector runs. # void deleteFF_Fpointer()