Log in

No account? Create an account
'Twas brillig, and the slithy toves did gyre and gimble in the wabe [entries|archive|friends|userinfo]

[ website | Beware the Jabberwock... ]
[ deviantArt | the-boggyb ]
[ FanFiction | Torkell ]
[ Tumblr | torkellr ]

[Random links| BBC news | Vulture Central | Slashdot | Dangerous Prototypes | LWN | Raspberry Pi]
[Fellow blogs| a Half Empty Glass | the Broken Cube | The Music Jungle | Please remove your feet | A letter from home]
[Other haunts| Un4seen Developments | Jazz 2 Online | EmuTalk.net | Feng's shui]

[Tuesday 14th March 2006 at 11:00 am]

[Tags|, ]
[Feeling |annoyedannoyed]

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.
Link | Previous Entry | Share | Flag | Next Entry[ 3 pennies | Penny for your thoughts? ]

[User Picture]From: pteppic
Tuesday 14th March 2006 at 1:13 pm (UTC)
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.
(Reply) (Thread)
From: pewterfish
Tuesday 14th March 2006 at 2:14 pm (UTC)
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.
(Reply) (Parent) (Thread)
[User Picture]From: boggyb
Wednesday 15th March 2006 at 12:00 pm (UTC)
A quick look through the docs shows that Java will let me tell the VM to run any finalizers on discarded objects (System.runFinalizers()), but says that this only suggests to the VM to do this. Java also by default does not run finalisers on exit, but this can be changed. The method to do this (System.runFinalizersOnExit()) is deprecated because apparently it can result in live objects being finalized while they're accessed by other threads.

I can tell Java to run the garbage collector (System.gc()), but again this only suggests to the VM that garbage collection might be a good idea.
(Reply) (Parent) (Thread)