Hey I'm testing out Runtime.freeMemory() with this code:
Runtime runtime = Runtime.getRuntime(); long freeMemory = runtime.freeMemory(); // This is some arbitary factor that should work <= 1 double factor = 0.8; int size = (int) (factor * freeMemory); byte testArray = new byte[size];
I'm creating a byte array of size close to the freeMemory value. For some reason, especially when I limit the memory of the program to around 8MB, the code throws an OutOfMemory exception for any factor > 0.55. This really doesnt make sense, surely freeMemory means freeMemory, I expect it to be a little out, but not double what actually is free.
Any suggestions on whats going on? Thanks
(Note in my tests im limiting the memory available to the program to 8MB or 16MB, using -Xmx8M etc.)