From: Delaney, T. <tde...@av...> - 2002-10-20 23:56:12
|
> From: pd...@qu... [mailto:pd...@qu...] > > I'm running Jython on Windows (NT, XP). > > #1. If I 'open' a file (mode 'wb') and write() to it, the > file ends up > truncated if I forget to close() it before the script exits. > This seems to be > different behavior to Python (and Perl etc). If I close() it > is is correcly > flushed and the file is complete on script exit. Jython uses Java's garbage collection, not reference counting. So the file will only be flushed an closed when the output stream is collected. However, finalisers will not be called when the Java VM quits, so the flush never occurs. You should *never* rely on garbage collection mechanisms (reference-counted or otherwise) to clean up resources other than memory. Always clean up such resources in a finally: block. There is no guarantee that CPython will continue to use reference counting (CPython 2.0+ have garbage collection which breaks cycles, allowing the reference counting semantics to continue, but there are cases when it punts). Tim Delaney |