I am implementing an external sort for a big file (~30GB), so after I have written the chunks in disk, I create chunks
times BufferedReader(new OutputStreamWriter(new FileOutputStream(outputPath), "UTF-8"), maxBufferSize)
being maxBufferSize = Runtime.getRuntime().freeMemory() / chunks
. However I get a OutOfMemory
Exception.
I guess that the garbage collector didn't have time enough to clean the memory (when I stop with the debugger it does not throw the exception), but in that case, why Runtime.getRuntime().freeMemory()
is given that result?
Is it possible to explicitly call the garbage collection or the only option is sleep the process for some time?