does python have useless destructors?

Carl Banks imbosol at aerojockey.invalid
Sun Jun 13 20:30:36 CEST 2004


Donn Cave wrote:
> 
> 
> Quoth Carl Banks <imbosol at aerojockey.invalid>:
> ...
> | These are silly examples, of course, but with more intricate stuff (or
> | with code by other people who are always less disciplined than you)
> | this can become a real problem.  Face it, people, it's ludicrous to
> | rely on the garbage collector to finalize stuff for us.
> 
> `Face it?'  We're not the ones talking about preposterous hypothetical
> cases and hand-waving claims about intricate code written by people
> who don't know what they're doing.

I was talking about intricate (as in slightly more intricate than a
simple open and close) code written by people who know what they're
doing but have to use code from other people who also claim to "know
what they're doing."


>  There's boatloads of Python code
> with constructs like the text = open(file, 'r').read() usage proposed
> in this thread, and it's truly no problem.

That's about as complex as you can get and still make that claim.  As
soon as the object gets bound to something, problems can (and will)
happen.


[snip]
> I don't need to know whether my function is the sole user of an object
> and it falls to me to free it when I'm done, because the system takes
> care of that.  I get it, I use it, I forget about it. 

The problem is, you can't always afford to forget about it.  Sometimes
you have to make sure that at this point in the program, this resource
has been released.

If you're relying on garbage collection to do that for you, you're
asking for trouble.


-- 
CARL BANKS                      http://www.aerojockey.com/software
"If you believe in yourself, drink your school, stay on drugs, and
don't do milk, you can get work." 
          -- Parody of Mr. T from a Robert Smigel Cartoon



More information about the Python-list mailing list