Heap Space, JAVA API

Hello users!

I have written a test-framework in order to conduct some tests of my es-server, this work perfectly except when running some large-scale tests which includes about 500 000 to 1 000 000 queries. In this case I get the Java heap space exception, OutOfMemoryError. Why does this occur? Is it because ES does not garbage collect properly? Could the problem be that the Elasticsearch instance in running too long? And maybe I should close it and start a new one for each search string? Below you can find a stack trace of the exception.

Thanks,
James Ford

Exception in thread "elasticsearch[cached]-pool-1-thread-1" java.lang.OutOfMemoryError: Java heap space
at org.elasticsearch.common.compress.lzf.BufferRecycler.allocOutputBuffer(BufferRecycler.java:96)
at org.elasticsearch.common.io.stream.LZFStreamOutput.(LZFStreamOutput.java:60)
at org.elasticsearch.common.io.stream.CachedStreamOutput.newEntry(CachedStreamOutput.java:37)
at org.elasticsearch.common.io.stream.CachedStreamOutput.popEntry(CachedStreamOutput.java:114)
at org.elasticsearch.transport.netty.NettyTransport.sendRequest(NettyTransport.java:454)
at org.elasticsearch.transport.TransportService.sendRequest(TransportService.java:181)
at org.elasticsearch.transport.TransportService.submitRequest(TransportService.java:162)
at org.elasticsearch.transport.TransportService.submitRequest(TransportService.java:156)
at org.elasticsearch.client.transport.TransportClientNodesService$SimpleNodeSampler.sample(TransportClientNodesService.java:269)
at org.elasticsearch.client.transport.TransportClientNodesService$ScheduledNodeSampler.run(TransportClientNodesService.java:245)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at org.elasticsearch.common.compress.lzf.BufferRecycler.allocOutputBuffer(BufferRecycler.java:96)
at org.elasticsearch.common.io.stream.LZFStreamOutput.(LZFStreamOutput.java:60)
at org.elasticsearch.common.io.stream.CachedStreamOutput.newEntry(CachedStreamOutput.java:37)
at org.elasticsearch.common.io.stream.CachedStreamOutput.popEntry(CachedStreamOutput.java:114)
at org.elasticsearch.transport.netty.NettyTransport.sendRequest(NettyTransport.java:454)
at org.elasticsearch.transport.TransportService.sendRequest(TransportService.java:181)
at org.elasticsearch.client.transport.action.support.BaseClientTransportAction.execute(BaseClientTransportAction.java:72)
at org.elasticsearch.client.transport.support.InternalTransportClient$16.doWithNode(InternalTransportClient.java:256)
at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:179)
at org.elasticsearch.client.transport.support.InternalTransportClient.search(InternalTransportClient.java:254)
at org.elasticsearch.client.transport.TransportClient.search(TransportClient.java:310)
at org.elasticsearch.client.action.search.SearchRequestBuilder.doExecute(SearchRequestBuilder.java:697)
at org.elasticsearch.client.action.support.BaseRequestBuilder.execute(BaseRequestBuilder.java:56)
at org.elasticsearch.client.action.support.BaseRequestBuilder.execute(BaseRequestBuilder.java:51)