ENH: add _clear_internal_caches function to simplify memory leak debugging - #31321
MaartenBaert wants to merge 1 commit into
Conversation
…gging This is analogous to sys._clear_internal_caches in cpython
|
Maybe it would be better to simply disable these caches with an environment variable that gets checked once when NumPy is imported? That would add one extra comparison with an integer in the allocation fast path but I doubt that's a big deal. We already have a numpy/numpy/_core/src/multiarray/alloc.c Lines 35 to 48 in 200f11c Of course that doesn't help anyone who can't build their own NumPy, but also I'd be surprised if anyone doing this sort of memory leak debugging couldn't build their own NumPy. I'd be fine with adding a more generic |

PR summary
This PR adds a
_clear_internal_cachesfunction to the multiarray module, analogous tosys._clear_internal_cachesin cpython.I added this to simplify debugging the memory leak in #31320 and thought it might make sense to submit this as a separate PR. I'm not sure what the best place for this is and what other caches exist in numpy that may need clearing, I just included the two that were showing up as false positives in my own memory leak testing.
AI Disclosure
The code was written by Claude Sonnet 4.6.