<p dir="ltr"><br>
On Nov 23, 2014 4:10 AM, "Patrick Stinson" <<a href="mailto:patrickkidd@gmail.com">patrickkidd@gmail.com</a>> wrote:<br>
> m = types.ModuleType('mine')<br>
> exec(s, m.__dict__)<br>
> print('deleting...')<br>
> m = None<br>
> print('done')<br>
><br>
> and the output is:<br>
><br>
> deleting...<br>
> done<br>
> __del__<br>
><br>
> I the “__del__" to come between “deleting…” and “done”. This is not being run from the interactive interpreter by via a .py file.</p>
<p dir="ltr">This suggests the presence of a reference cycle, since the object is deleted afterward by the garbage collector. One cycle here is that the __del__ function has a reference to the module's globals dict, which has a reference to the class instance, which has a reference to the class, which has a reference back to the function. There may be other cycles here as well, but it may also be that the module object itself isn't part of them.</p>