Hi,<br><br>Currently in my ipython-app branch, InteractiveShell is a real object that can be instantiated:<br><br>ip = InteractiveShell()<br><br>But, when you do:<br><br>del ip<br>gc.collect()<br><br>The InteractiveShell.__del__ does *not* get called.  This is not too surprising given how garbage collection<br>
works in python:<br><br>*  We have cycles to InteractiveShell all over the place (everybody points to it!)<br>*  In Python cycles + __del__ methods => some objects can't be collected even when gc.collect() is run.<br>
<br>I would like to resolve this problem and I see two ways of accomplishing it:<br><br>1.  Begin to use weakrefs everywhere.  This would break all our cycles and would probably be a good idea<br>anyways.  If we do this with discipline, we might be able to get a __del__ method called to do cleanup<br>
(removing sys.*hook, removing things injected into __builtin__, etc.).<br><br>2.  Add a .cleanup() method that does all the cleanup by hand.  This won't break cycles, but it would ensure<br>that the InteractiveShell had "detached" from everything outside of itself.  If we go this way, and drop 2.4<br>
support, we could make InteractiveShell a context manager and have cleanup called when the context<br>exists.<br><br>My goal is that we could create and destroy InteractiveShell instances (for testing, etc.) whenever we want<br>
or need and they would always clean up after themselves.<br><br>If we don't go this route, then I think we should make InteractiveShell a singleton.<br><br>Thoughts?<br><br>Cheers,<br><br>Brian<br>