# Clear the memory in Elasticsearch

**URL:** https://discuss.elastic.co/t/clear-the-memory-in-elasticsearch/10014
**Category:** Elasticsearch
**Created:** [December 10, 2012, 9:54am UTC](https://discuss.elastic.co/t/clear-the-memory-in-elasticsearch/10014 "2012-12-10T09:54:33Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![DH1](https://avatars.discourse-cdn.com/v4/letter/d/65b543/32.png) [@DH1](https://discuss.elastic.co/u/DH1)
#### Post date: [December 10, 2012, 9:54am UTC](https://discuss.elastic.co/t/clear-the-memory-in-elasticsearch/10014/1 "2012-12-10T09:54:33Z")

</div>

Hi, everyone.

I am currently trying to find out how memory works in elasticsearch.  
I am using BigDesk to monitor the heap space of my nodes, and it seems to  
me that the heap memory only start to be freed when it is almost all used  
up. Is that normal?  
It seems to cause OOM errors when making big queries .  
When the node has just started, they work fine (a bit lenghty, but the  
cache effect hasn't kicked in yet, so nothing special).  
But when several other queries have been made, I start getting OOM errors  
that ultimately lead to a restart of the cluster.  
The heap memory does not seem to clear with enough efficiency to make room  
for the new query. Does that seem logical? Is there a setting somewhere to  
define when to clear the memory? Is there a way to force-clear the heap  
memory?  
The flush API doesn't seem to do anything in that regard.

Thanks for any insights on the subject.

--

---

<div class="post-metadata">

### Author: ![Karussell\_2](https://avatars.discourse-cdn.com/v4/letter/k/54ee81/32.png) [@Karussell\_2](https://discuss.elastic.co/u/Karussell_2)
#### Post date: [December 10, 2012, 11:19am UTC](https://discuss.elastic.co/t/clear-the-memory-in-elasticsearch/10014/2 "2012-12-10T11:19:34Z")

</div>

you miss a lot of details: how much memory do you have for elasticsearch,  
how many docs/index size/..., what queries are you running etc

> to be freed when it is almost all used up. Is that normal?

yes, that is the java way

Peter.

On Monday, December 10, 2012 10:54:33 AM UTC+1, DH wrote:

> Hi, everyone.
> 
> I am currently trying to find out how memory works in elasticsearch.  
> I am using BigDesk to monitor the heap space of my nodes, and it seems to  
> me that the heap memory only start to be freed when it is almost all used  
> up. Is that normal?  
> It seems to cause OOM errors when making big queries .  
> When the node has just started, they work fine (a bit lenghty, but the  
> cache effect hasn't kicked in yet, so nothing special).  
> But when several other queries have been made, I start getting OOM errors  
> that ultimately lead to a restart of the cluster.  
> The heap memory does not seem to clear with enough efficiency to make room  
> for the new query. Does that seem logical? Is there a setting somewhere to  
> define when to clear the memory? Is there a way to force-clear the heap  
> memory?  
> The flush API doesn't seem to do anything in that regard.
> 
> Thanks for any insights on the subject.

--

---

<div class="post-metadata">

### Author: ![otisg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/otisg/32/492_2.png) [@otisg](https://discuss.elastic.co/u/otisg)
#### Post date: [December 10, 2012, 9:43pm UTC](https://discuss.elastic.co/t/clear-the-memory-in-elasticsearch/10014/3 "2012-12-10T21:43:21Z")

</div>

Hi,

On Monday, December 10, 2012 4:54:33 AM UTC-5, DH wrote:

> Hi, everyone.
> 
> I am currently trying to find out how memory works in elasticsearch.  
> I am using BigDesk to monitor the heap space of my nodes, and it seems to  
> me that the heap memory only start to be freed when it is almost all used  
> up. Is that normal?

That's typical, but you can control it with a few knobs like -XX:MinHeapFreeRatio,  
-XX:SurvivorRation, -XX:TargetSurvivorRatio, etc.

Have a look  
at [Java HotSpot VM Options](http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html)

## Otis

ELASTICSEARCH Performance Monitoring - [Sematext Monitoring | Infrastructure Monitoring Service](http://sematext.com/spm/index.html)  
Search Analytics - [Cloud Monitoring Tools & Services | Sematext](http://sematext.com/search-analytics/index.html)

> It seems to cause OOM errors when making big queries .  
> When the node has just started, they work fine (a bit lenghty, but the  
> cache effect hasn't kicked in yet, so nothing special).  
> But when several other queries have been made, I start getting OOM errors  
> that ultimately lead to a restart of the cluster.  
> The heap memory does not seem to clear with enough efficiency to make room  
> for the new query. Does that seem logical? Is there a setting somewhere to  
> define when to clear the memory? Is there a way to force-clear the heap  
> memory?  
> The flush API doesn't seem to do anything in that regard.
> 
> Thanks for any insights on the subject.

--

---

<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:00am UTC](https://discuss.elastic.co/t/clear-the-memory-in-elasticsearch/10014/4 "2017-07-06T03:00:29Z")

</div>


