summaryrefslogtreecommitdiff
path: root/numpy/lib/npyio.py
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/lib/npyio.py')
-rw-r--r--numpy/lib/npyio.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py
index 3a575a048..c502e2cc5 100644
--- a/numpy/lib/npyio.py
+++ b/numpy/lib/npyio.py
@@ -10,6 +10,7 @@ import re
import sys
import itertools
import warnings
+import weakref
from operator import itemgetter
from cPickle import load as _cload, loads
@@ -108,7 +109,8 @@ class BagObj(object):
"""
def __init__(self, obj):
- self._obj = obj
+ # Use weakref to make NpzFile objects collectable by refcount
+ self._obj = weakref.proxy(obj)
def __getattribute__(self, key):
try:
return object.__getattribute__(self, '_obj')[key]
@@ -212,6 +214,7 @@ class NpzFile(object):
if self.fid is not None:
self.fid.close()
self.fid = None
+ self.f = None # break reference cycle
def __del__(self):
self.close()