Lately I took a look at the
TweetBox Twitter client which is build with
JavaFX(
© 2008-2009 Sun Microsystems). I thought it would be fun to check whether a Java based Twitter client would have less memory usage problems than those popular
Adobe Air(
© Adobe) based clients, such as
Tweetdeck. If you search for memory leak in
Twitter you will get a lot of references about
Tweetdeck, which might only be caused by it's a popularity. Because
JavaFX is JVM based it actually has an advantage in the area of memory usage analysis over
Adobe Air.
TweetBox currently does not perform very well, but the author is working on improving it and I also tried to help him out a little bit.
When looking for memory usage using my
favorite tool I was quite surprised to see the high overhead of variables in JavaFX.
Let's have a look at some numbers for the shallow size of variables (32 bit CPU):
Shallow Size
Boolean: 24 bytes (Yes, this is for one bit of information)
Integer: 24 bytes
Objects: 24 bytes
Floats: 24 bytes
Sequence: 32 bytes(never smaller than 48 bytes)
JavaFX objects seems to have a relatively large number of fields, so this overhead might be really become significant, also as always, it depends on your application.
For comparsion a boolean in Java takes 1 byte and Objects have a general overhead of 8 bytes (SUN 32 bit JVM). For details about the memory usage of Java objects check my post
here.
But when looking at the retained size it even gets worse. Due to JavaFX's fancy binding mechanism those objects often reference other objects which causes the retained size to "explode".
Average "Retained size"
Boolean: 111 bytes Integer: 53 bytes
Objects: 76 bytes
Floats: 53 bytes
Sequence: 84 bytes
111 bytes average (!) for a Boolean is absurdly high and I'm not sure yet whether that's because Tweetbox using it in the wrong way or because of a bug. It is caused by long chain's of com.sun.javafx.runtime.location.DynamicDependentLocation.
I have no clue what that is and even Google doesn't seem to know.
I hope JavaFX's memory usage will improve over time. Right know you have to be very careful to not run into memory usage problems.