Hello,
Seems related to #1514.
Images are automaticly retrives by HtmlUnit and read with ImageIO. ImageIO caches images on disk (on tmp dir) and leak file descriptor.
It may be related to
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7166379
I have joined a fast patch that override finalize and close and free imagereader
Here is a human test (difficult to automatize):
@Test public void imageIoLake() { System.setProperty("java.io.tmpdir", "D:\\temp\\io\\") WebClient webClient = Helper.newWebClient() final HtmlPage page = webClient.getPage("http://www.pcinpact.com"); DomNodeList<HtmlImage> elements = page.getElementsByTagName("img") elements.each { try { it.getWidth() } catch (Exception e) { e.printStackTrace() } } webClient.closeAllWindows() System.gc(); Thread.sleep(100000000) }
The test must set into brace with System.gc() outside (or nullify variable)
I need to reproduce, to justify adding the patch.
Here is a working test that fails. The issue is reproduced on JDK 7u40.
Images of yahoo websites are downloaded (with downloadImageIfNeeded/readImageIfNeeded). "htmlunit" temp directory contains "imageioXXX.tmp" files. ImageIO holds file descriptor on these files. They cannot be deleted until the JVM exit.
With the patch, the finalize method dispose the ImageIO image and release the file descriptor.
@Test
public void imageIoLake() throws IOException {
I guess you meant "Assert.assertTrue(imgs.length == 0);"
Even putting in finalize doesn't delete all images, I used the below code
@all: what do you think?
HtmlImage.finalize() has been added in SVN.
However, my tests with eclipse wasn't promising, as finalize() was called for only 5 images.
Anyhow, as it doesn't hurt, it has been committed.
GC is poorly predictable. In my test I got 0 images, but I call gc more than 1 time.
Maybe you can try to call it inside the while loop. Anyway thanks for the addition