File.deleteOnExit() is evil | Just like that...
Every time we use "ImageIO.write(img, "png", outStream)" a temporary file is created, and the "deleteOnExit()" function is called on that temporary file. Every "deleteOnExit()" allocates a "struct dlEntry" in the shared "io_util.c" native source file. This "struct dlEntry" is about 1K in size, and will never be freed until the system exits, so every time we do an ImageIO.write(), we take up another 1K of memory! No package should use "deleteOnExit()" dynamically – it guarantees a memory leak.
One workaround is to disallow the use of cache files by passing false to the static ImageIO.setUseCache() method. This avoids the deleteOnExit() problems and should have little adverse effect on performance, especially in the case of server-side applications working with relatively small images. This memory leak is a major reliability issue for developers using ImageIO in their server side applications.
Read full article from File.deleteOnExit() is evil | Just like that...
No comments:
Post a Comment