win32 file locking

Andrew Bennetts andrew at canonical.com
Wed May 25 06:41:09 BST 2005


On Tue, May 24, 2005 at 10:37:29PM -0500, John A Meinel wrote:
[...]
> 
> Also, I noticed that Branch() does not automatically unlock the lockfile
> when it is done. Shouldn't that be done in the deconstructor?

__del__ should be avoided, particularly for releasing resources.  It may be
called at arbitrary, unpredictable times by the interpreter -- if at all.
In particular, if an object with a __del__ is in an unreachable reference
cycle, the CPython garbage collector will just append the entire cycle to
gc.garbage rather than try to figure out how on earth to deallocate it
(there are periodic discussions of this limitation on python-dev, e.g.
http://mail.python.org/pipermail/python-dev/2005-May/053926.html).

So __del__ tends to lead to memory leaks and objects *not* being released.
Even if they do get released, it can happen much later than you expect,
depending on when the garbage collector decides to look at that object.

Just release resources explicitly.

A quick grep shows me that bzr currently only uses __del__ in two places,
and only in test code.  I recommend keeping it that way.

-Andrew.





More information about the bazaar mailing list