def __del__(self): print 'MyChild deleted', id(self) class MyParent(object): def __init__(self): self.children = [] def addChild(self): child = MyChild(self) self.children.append(child) return child def __del__(self): print 'MyParent deleted', id(self) if __name__ == "__main__": # create a bunch in a loop: for i in range(50): print "iteration:", i p = MyParent() p.addChild() p.addChild() p.addChild() print "ref count:", sys.getrefcount(p) print "mem_use:", mem_check.get_mem_use() del p gc.collect()
from ext4 import * import time, string import mem_check while True: #string_peek3(string.ascii_lowercase) string_peek4(string.ascii_lowercase) print "mem_use: %f MB" % mem_check.get_mem_use()
print 'MyChild deleted', id(self) class MyParent(object): def __init__(self): self.children = [] def addChild(self): child = MyChild(self) self.children.append(child) return child def __del__(self): """ __del__ defined to defeat GC""" print 'MyParent deleted', id(self) if __name__ == "__main__": # create a bunch in a loop: for i in range(50): print "iteration:", i p = MyParent() p.addChild() p.addChild() p.addChild() print "ref count:", sys.getrefcount(p) print "mem_use: %f MB" % mem_check.get_mem_use() del p print "collected", gc.collect()
def __del__(self): print "MyChild deleted", id(self) class MyParent(object): def __init__(self): self.children = [] def addChild(self): child = MyChild(self) self.children.append(child) return child def __del__(self): print "MyParent deleted", id(self) if __name__ == "__main__": # create a bunch in a loop: for i in range(50): print "iteration:", i p = MyParent() p.addChild() p.addChild() p.addChild() print "ref count:", sys.getrefcount(p) print "mem_use:", mem_check.get_mem_use() del p gc.collect()