Python vs Java garbage collection?

Courageous jkraska at san.rr.com
Mon Dec 23 01:52:29 EST 2002


>Yes, that's essentially exactly what I said a few posts ago:  "Even in
>Python, you should make sure that code which acquires [external]
>resources releases them in a timely manner."

I wish I could provide an objective metric for this, but I think it's
mostly opinion and subjective. One bit of objective truth is this,
however: file.close() says quite clearly "I'm done with this." While
one can infer that if the reference to file no longer exists, one is
done with the file, that's an additional inferential step. Explicit
is better than implicit, sometimes. I think this is one of those times.

As another data point, if I a junior programmer on one of my projects
relied on implicit file closing, I'd politely insist that he not.

It's simply my gut feel and years of experience which say "closing
explicitly is best practice."

C//




More information about the Python-list mailing list