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

Matthew Brett matthew.brett at gmail.com
Sat May 18 20:17:06 EDT 2013


Hi,

On Sat, May 18, 2013 at 5:07 PM, Aron Ahmadia <aron at ahmadia.net> wrote:
>
> On Sun, May 19, 2013 at 1:00 AM, Matthew Brett <matthew.brett at gmail.com>
> wrote:
>>
>> Following on from Josef's and Robert's posts, I wrote a
>> `check_refs_for` context manger that does this:
>
>
> Newbie question but what is context manager in this, ermnn, context?

:)  - I mean a context manager in the sense of a thing that does the
with statement:

http://docs.python.org/2/library/stdtypes.html#typecontextmanager

Is that what you meant?

> That's a cool test, maybe rename it to:
>
> assert_no_refs_to(C):

Not a bad name - thanks.

> And I haven't seen the code, but I assume it...
>
> - asserts no C refs
> - disables garbage collector
>
> - code
>
> - asserts no C refs
> - re-enables garbage collector

Well - on entry to the with-block it:

Turns off garbage collection
Creates the object using the input arguments to 'check_refs_for'
Collects a weak reference to the new object
Passes the new object into the context of the with-block - the 'as
obj' part of the with statement

After the with-block is done it

deletes its own reference to the object
asserts that the weakref is now None
turns garbage collection back on (or rather, restores it to the previous state).

I've attached the code too ...

Cheers,

Matthew
-------------- next part --------------
A non-text attachment was scrubbed...
Name: check_refs.py
Type: application/octet-stream
Size: 1951 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20130518/4b576b20/attachment-0002.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_check_refs_for.py
Type: application/octet-stream
Size: 2976 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20130518/4b576b20/attachment-0003.obj>


More information about the SciPy-Dev mailing list