FIX: Prevent memory leak in RawArray by removing data from _init_kwargs - #14360
Open
adi-coderr wants to merge 1 commit into
Open
adi-coderr wants to merge 1 commit into
adi-coderr wants to merge 1 commit into
Conversation
adi-coderr
requested review from
agramfort,
drammock and
larsoner
as code owners
September 30, 2026 08:28
|
Hello! 👋 Thanks for opening your first pull request here! ❤️ We will try to get back to you soon. 🚴 |
This branch has not been deployed
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.
This fixes: #14074
Description of the problem
BaseRaw.__init__captures constructor arguments inself._init_kwargsvia_get_argvalues(). ForRawArray, this includes the complete signal array (self._init_kwargs["data"]).When operations such as
resample()orcrop()replaceraw._data,self._init_kwargs["data"]continues to hold a strong reference to the original array, preventing it from being garbage collected. In addition,raw.copy()deep-copies_init_kwargs, duplicating the unused dead array and multiplying memory usage.Solution
"data"fromself._init_kwargsinRawArray.__init__immediately aftersuper().__init__(...)._test_raw_reader(RawArray, ...)intest_array.pyto passtest_kwargs=False(since in-memoryRawArrayobjects cannot be re-instantiated without data like disk-based readers).weakrefregression check intest_array_copy()ensuringraw._datareplacement allows the original array to be collected and that"data"is absent from_init_kwargs.Assistance Disclosure
In accordance with the MNE AI-assistance policy in CONTRIBUTING.md, an AI coding assistant was used to help trace the frame inspection in
_get_argvalues()and draft the regression test.