Repository navigation
Fix memory leak: implement __deepcopy__ for ExtraCoords and GlobalCoords - #991
Closed
sumitsaraswat362 wants to merge 3 commits into
Closed
sumitsaraswat362 wants to merge 3 commits into
sumitsaraswat362 wants to merge 3 commits into
Conversation
Member
|
We've run with #996 instead, but thanks. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #989
Description
This PR addresses the issue where
ExtraCoordsandGlobalCoordsretain a plain reference to their parent cube in_ndcube. Because they did not have a custom__deepcopy__, callingdeepcopy()on either object would inadvertently deep-copy the entire parent cube (including data, uncertainty, and mask).This resulted in massive memory allocation spikes during arithmetic operations (e.g.
cube * 2) and inNDCube._new_instance, as two full copies of the cube were created and immediately discarded when the coordinates were reassigned.Fix:
Implemented
__deepcopy__in bothExtraCoordsandGlobalCoordsto copy the internal tables but leave_ndcubeasNone. The descriptor handles re-pointing the_ndcubereference upon assignment to the new cube. This effectively removes the memory leak and significantly reduces the peak memory footprint of derived cubes and arithmetic operations.(Following the smallest/safest change recommended in #989 Option 1)