Asaf Las <roeg...@gmail.com> Wrote in message: > On Wednesday, January 22, 2014 10:56:30 AM UTC+2, Frank Millman wrote: >> >> class MainObject: >> def __init__(self, identifier): >> self._del = delwatcher('MainObject', identifier) >> class delwatcher: >> def __init__(self, obj_type, identifier): >> self.obj_type = obj_type >> self.identifier = identifier >> log('{}: id={} created'.format(self.obj_type, self.identifier)) >> def __del__(self): >> log('{}: id={} deleted'.format(self.obj_type, self.identifier)) >> If you do find that an object is not being deleted, it is then >> trial-and-error to find the problem and fix it. It is probably a circular >> reference >> >> Frank Millman > > Thanks Frank. Good approach! > > One question - You could do: > class MainObject: > def __init__(self, identifier): > self._del = delwatcher(self) > then later > > class delwatcher: > def __init__(self, tobject): > self.obj_type = type(tobject) > self.identifier = id(tobject) > ... > > when creating delwatcher. Was there special reason to not to use them? > is this because of memory is reused when objects are deleted > and created again so same reference could be for objects created > in different time slots? >
I couldn't make sense of most of that. But an ID only uniquely corresponds to an object while that object still exists. The system may, and will, reuse iD's constantly. -- DaveA -- https://mail.python.org/mailman/listinfo/python-list