Pular para o conteúdo principal

Postagens

Mostrando postagens com o rótulo memory

How java.io.File.deleteOnExit can cause leaks

If you didn't know this, now you know: calling   java.io.File.deleteOnExit can cause leaks. This is described by  Yan in his java.io.File.deleteOnExit() is evil post. You may think that you develop applications that won't create too much files and does not runs for many hours, but in an application server running for days this may be a real problem. In this post I just wanted to share how it can quickly grow your heap memory when dealing a lot of files. See the code below: Notice that the code deletes the reference to the created file object (nullify it) so it can be collected by the garbage collector. At some point the program will explodes with OutOfMemory error probably due the high amount of String created (when running with small heap). If you increase the heap and use some tool to get a heap dump of your running application you will see memory content on the *static* Linked used in DeleteOnExitHook class. We can do this in runtime by using jvisualvm (a too...