ownership problem?

Donn Cave donn at u.washington.edu
Mon Nov 21 21:59:14 CET 2005

In article <dy8gf.3763$3o6.904548 at twister.southeast.rr.com>,
 Jeffrey Schwab <jeff at schwabcenter.com> wrote:
> Yes it is.  Memory is only one type of resource.  There are still files 
> and sockets to close, pipes to flush, log messages to be printed, GDI 
> contexts to free, locks to release, etc.  In C++, these things are 
> generally done by destructors, which are called automatically and 
> deterministically.  I am not a Python Guru, but in Perl, Java, and other 
> languages that have built-in garbage collectors, these tasks have to be 
> done explicitly.  I find that this forces a procedural approach, even in 
> an otherwise object-oriented program.
> If you want something like automatic garbage collection in C++, I 
> recommend the use of Factories with destructors that release the 
> Factories' products.  The zeitgeist in c.l.c++.moderated seems to prefer 
> the use of smart (reference-counted) pointers, which also rely on 
> destructors to release resources automatically.  Plentry of free, 
> open-source implementations are available.

You may be gratified to learn that Python's main storage model
is reference counted objects, and when an object falls out of
all referenced scopes its finalizers run immediately.

This is however true only of the C implementation.  The Java
implementation naturally has Java's limitations in this matter,
so documentation generally avoids the issue.  The C implementation
has been around for over a decade, wonder if it had any influence
on your C++ zeitgeist?

   Donn Cave, donn at u.washington.edu

More information about the Python-list mailing list