<div class="gmail_quote">On Tue, Oct 20, 2009 at 8:01 AM, Antoine Pitrou <span dir="ltr"><<a href="mailto:solipsis@pitrou.net">solipsis@pitrou.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
You don't need __del__, a weakref is good enough since you only need to remember<br>
an adequate string representation of the object:<br>
<br>
   def error_not_closed(_, r=repr(self)):<br>
      log_an_error('%s not closed properly' % r)<br>
    self._wr_not_closed = weakref.ref(self, error_not_closed)<br></blockquote></div><br>Thank you!  This is a much simpler recipe than the others I have seen.  It should probably be placed right in the documentation for __del__, as a suggested alternative.<br>
<br>Having direct support from the garbage collector would still be more memory efficient (instead of requiring a weakref and a bound function object), but it will do for many purposes in a pinch.<br><blockquote style="margin: 1.5em 0pt;">
--<br>
Daniel Stutzbach, Ph.D.<br>
President, <a href="http://stutzbachenterprises.com">Stutzbach Enterprises, LLC</a>
</blockquote>