torkell: (Default)
[personal profile] torkell
Today's discovery: Java will not flush file streams for you. If you open a BufferedWriter, write some stuff to it, and then don't call close() on it, then Java will happily throw the remains of the buffer away.

This is probably related to the lack of destructors in Java, and the complete and utter uselessness of Object.finalize() - the method that's like a destructor, except it only gets called if the garbage collector runs, and then only if the garbage collector feels like it.

Date: 2006-03-14 01:13 pm (UTC)
From: [identity profile] pteppic.livejournal.com
Does Java have a wait for pending finalizers like .NET? Could be your friend here...

And by now, surely Java will let you directly call the GC.

Date: 2006-03-14 02:14 pm (UTC)
From: [identity profile] pewterfish.livejournal.com
Since Java 1.2, I believe. System.gc() is your friend, assuming your code is written in such a way that the garbage collector can safely do its thing.

You should be flushing your buffers anyway. Dumping the buffer to stream on close isn't always the right thing to do if the thread of execution terminates unexpectedly.

January 2026

S M T W T F S
     123
45678910
11121314151617
18192021222324
25262728293031

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated May. 7th, 2026 08:46 pm
Powered by Dreamwidth Studios