Created
June 23, 2010 21:47
-
-
Save anonymous/450606 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gc | |
import sys | |
sm = sys.modules.copy() | |
print len(gc.get_objects()) # 4075 | |
import httplib | |
print len(gc.get_objects()) # 7064 | |
sys.modules.pop('httplib') | |
gc.collect() | |
print len(gc.get_objects()) # 7064 | |
del httplib | |
gc.collect() | |
print len(gc.get_objects()) # 6747 | |
sys.modules = sm | |
gc.collect() | |
print len(gc.get_objects()) # 6747 | |
globals().clear() | |
import gc | |
gc.collect() | |
print len(gc.get_objects()) # 6747 | |
locals().clear() | |
import gc | |
gc.collect() | |
print len(gc.get_objects()) # 6747 | |
g = {} | |
exec 'import httplib' in g | |
del g | |
gc.collect() | |
print len(gc.get_objects()) # back to 7064 | |
from types import ModuleType | |
import sys | |
print len(gc.get_objects()) # 7064 | |
sys.modules['httplib'] = ModuleType('httplib') | |
print len(gc.get_objects()) # 7066 | |
for key in sys.modules.keys(): | |
del sys.modules[key] | |
gc.collect() | |
print len(gc.get_objects()) # 7064 | |
import httplib | |
for attr in dir(httplib): | |
setattr(httplib, attr, None) | |
gc.collect() | |
print len(gc.get_objects()) # 6749 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment