I have been trying to solve Java Heap Space OutOfMemory Exception thrown from my program that uses HTMLUnit API to visit pages (the pages have extensive javascripts so i choosed to use HTMLUnit for this). The program runs for about 1 hour and the memory exception is encountered. I tried different methods as suggested from other posts, but none solved this issue.
While the program runs on Linux: the linux TOP command shows the memory usage by this program is continuously increasing and reaches to 90% and then the OutOfMemory exception is thrown.
These are methods i tried to solve this issue:
1.increased heap space
2.run on jdk1.8
3.run on open jre1.7
4.used latest version of html unit i.e. htmlunit2.7
5.used webclient.close() method in finally block
List<WebWindow> windows = client.getWebWindows();
This list count increases in each new page visit, even if i close all the windows:
webclient.close()
I wonder what is the cause for increased memory usage by HTMLUnit and why program does not release memory even when webclient.close() method is called. Any suggestions related to this will be appreciated. Thank you.
EDIT:
static WebClient client; //this is class variable
public void parsePage(){
HtmlPage pages;
pages = client.getPage(myURL);
Document doc = Jsoup.parse(pages.asXml()); //Using JSOUP library here
client.close();
///do work on the Document
}