# Heap Space, JAVA API

**URL:** <https://discuss.elastic.co/t/heap-space-java-api/7196>\
**Category:** Elasticsearch\
**Created:** [April 2, 2012, 8:24am UTC](https://discuss.elastic.co/t/heap-space-java-api/7196 "2012-04-02T08:24:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![James\_Ford](https://avatars.discourse-cdn.com/v4/letter/j/e0b2c6/32.png) [@James\_Ford](https://discuss.elastic.co/u/James_Ford)\
**Post date:** [April 2, 2012, 8:24am UTC](https://discuss.elastic.co/t/heap-space-java-api/7196/1 "2012-04-02T08:24:34Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 3:34am UTC](https://discuss.elastic.co/t/heap-space-java-api/7196/2 "2017-07-06T03:34:00Z")

</div>


