def counted_init(init): if isShowMemory(): def wrapped_init(self, *args, **kw): name = self.__class__.__name__ assert type(name) is str if name not in counted_inits: counted_inits[name] = 0 counted_inits[name] += 1 init(self, *args, **kw) return wrapped_init else: return init
def counted_del(del_func = empty_del): if isShowMemory(): def wrapped_del(self): # This cannot be necessary, because in program finalization, the # global variables were assign to None. if counted_dels is None: return name = self.__class__.__name__ assert type(name) is str if name not in counted_dels: counted_dels[name] = 0 counted_dels[name] += 1 if del_func is not empty_del: del_func(self) return wrapped_del else: return empty_del
def counted_del(): assert isShowMemory() return _wrapped_del
def isCountingInstances(): return isShowMemory()