Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add explicit grid destroy when deleting Regridder #387

Merged
merged 3 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
What's new
==========

0.8.8 (unreleased)
------------------
* Fix ESMpy memory issues by explictly freeing the Grid memory upon garbage collection of ``Regridder`` objects. By `Pascal Bourgault <https://github.com/aulemahal>`_.

0.8.7 (2024-07-16)
------------------
* Cast grid sizes to python's int (another Numpy 2.0 fix). (:pull:`377`) By `Pascal Bourgault <https://github.com/aulemahal>`_.
Expand Down
12 changes: 12 additions & 0 deletions xesmf/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,12 @@ def _format_xroutput(self, out, new_dims=None):

return out

def __del__(self):
# Memory leak issue when regridding over a large number of datasets with xESMF
# https://github.com/JiaweiZhuang/xESMF/issues/53
self.grid_in.destroy()
self.grid_out.destroy()


class SpatialAverager(BaseRegridder):
def __init__(
Expand Down Expand Up @@ -1372,3 +1378,9 @@ def _format_xroutput(self, out, new_dims=None):
out.coords[self._lat_out_name] = xr.DataArray(self._lat_out, dims=(self.geom_dim_name,))
out.attrs['regrid_method'] = self.method
return out

def __del__(self):
# Memory leak issue when regridding over a large number of datasets with xESMF
# https://github.com/JiaweiZhuang/xESMF/issues/53
self.grid_in.destroy()
self.grid_out.destroy()
Loading