[SciPy-Dev] Circular reference in interp1d causing memory errors

Matthew Brett matthew.brett at gmail.com
Sun May 19 03:47:41 EDT 2013


Hi,

On Sat, May 18, 2013 at 5:00 PM, Matthew Brett <matthew.brett at gmail.com> wrote:
> Hi,
>
> On Sat, May 18, 2013 at 1:22 PM, Matthew Brett <matthew.brett at gmail.com> wrote:
>> Hi,
>>
>> On Sat, May 18, 2013 at 2:23 AM, Robert Kern <robert.kern at gmail.com> wrote:
>>> On Sat, May 18, 2013 at 8:11 AM, Matthew Brett <matthew.brett at gmail.com> wrote:
>>>
>>>> Is this the right analysis?  Is this the right patch?
>>>
>>> Sounds about right. The patch needs a comment explaining why, though,
>>> because the current code is a common pattern.
>>
>> Yes - maybe it's easier to make that clear by using unbound references
>> rather than doing it the crude way as in the previous patch.
>
> Following on from Josef's and Robert's posts, I wrote a
> `check_refs_for` context manger that does this:
>
>     >>> class C(object): pass
>     >>> with check_refs_for(C) as c:
>     ...     # do something
>     ...     del c
>
>     >>> class C(object):
>     ...     def __init__(self):
>     ...         self._circular = self # Make circular reference
>     >>> with check_refs_for(C) as c:
>     ...     # do something
>     ...     del c
>     Traceback (most recent call last):
>         ...
>     ReferenceError: Remaining reference(s) to object
>
> I was thinking of proposing it for scipy.misc in order to test my
> interpolate.py patch, but I wonder if it belongs in numpy.testing.
> What do y'all think?

Added context managers in scipy.misc, added interp1d patch

https://github.com/scipy/scipy/pull/2502

Cheers,

Matthew



More information about the SciPy-Dev mailing list