ironpython2
ironpython2 copied to clipboard
Allocating objects in try / except seems to pin the object for the life of the interpreter/scope
Running the following code as a file (ie save to test.py and then run "ipy test.py") shows that A(6) lasts till then end of the script whereas, if you run it as individual commands in ipy, then A(6) is disposed correctly:
import weakref
import gc
class A():
def __init__(self, test):
self.test = test
def __del__(self):
print "__del__ " + str(self.test)
# now show try / except
print "test 6"
try:
a = A(6)
except:
pass
del a
gc.collect(2)
print "'__del__ 6' is collected above in interactive mode (expected result) but not as a script"
print "'__del__ 6' happens after here if we're running as a script"
See https://github.com/IronLanguages/ironpython2/pull/269#discussion_r152788623 for initial discussion.