Do not store grids, destroy them after usage #402
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Cleanest solution to #401 I could think of. An alternative less breaking solution would be to simply revert #387.
Once the weights are generated, we do not need the ESMpy grids (or locstreams) anymore. In fact, before #24, the grid were "destroyed" (they memory explicitly released by ESMpy) once the regrid was done. That meant that
Regridder.grid_in
was still there and with most properties accessible, but most methods would fail, with a segmentation fault. When implementing the Spatial Averager, I needed to reuse grid objects for multiple ESMpy regrid calls, so I commented out the explicitdestroy
.As shown in JiaweiZhuang/xESMF#53, this creates a memory leak. #387 added these
destroy
back, as suggested by a comment on that thread. However, the moment they are executed seems to trigger #401.Here, I make it clear that we do not need the grids : they are never set as attributes of the Regridder and are destroyed once the weights are generated. The
destroy
happens in the children (instead of a backend function) because that is were the objects were created. If users use theBaseRegridder
with ESMpy objects directly, they should be unaffected.But this is breaking because
Regridder.grid_in
andRegridder.grid_out
do not exist anymore. Internally, we weren't really making use of them, but I don't know what are users are doing.