# Memory Optimization

**URL:** https://discuss.elastic.co/t/memory-optimization/12109
**Category:** Elasticsearch
**Created:** [May 24, 2013, 5:55am UTC](https://discuss.elastic.co/t/memory-optimization/12109 "2013-05-24T05:55:13Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Rajesh\_Tarle](https://avatars.discourse-cdn.com/v4/letter/r/3da27b/32.png) [@Rajesh\_Tarle](https://discuss.elastic.co/u/Rajesh_Tarle)
#### Post date: [May 24, 2013, 5:55am UTC](https://discuss.elastic.co/t/memory-optimization/12109/1 "2013-05-24T05:55:13Z")

</div>

Hi,

I have a doubt. when I start elastic search it's taking memory around 510MB  
.now I created around 7,00,000 records in four indexes then it's taking  
around 3.7GB memory.  
but when i remove all four indexes memory it's not free.(means it does not  
come to around 510MB).

My doubt is why Memory is not free after deleting the index.

Please help.

Thanks  
Rajesh

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)
#### Post date: [May 24, 2013, 7:11am UTC](https://discuss.elastic.co/t/memory-optimization/12109/2 "2013-05-24T07:11:07Z")

</div>

Hi Raj,

How much memory did you give to the JVM? It's very common for JVMs to not  
give back memory as soon as memory is not used anymore. They assume that if  
memory was needed at some point, it might be needed again soon, so they  
prefer keeping unused memory reserved instead of paying the cost to give  
memory back to the OS and then allocate it again a few minutes later.

--  
Adrien Grand

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Rajesh\_Tarle](https://avatars.discourse-cdn.com/v4/letter/r/3da27b/32.png) [@Rajesh\_Tarle](https://discuss.elastic.co/u/Rajesh_Tarle)
#### Post date: [May 24, 2013, 9:52am UTC](https://discuss.elastic.co/t/memory-optimization/12109/3 "2013-05-24T09:52:05Z")

</div>

Hi,  
Thanks for reply.  
I have given 4GB memory to the JVM.  
How can I free memory after deleting index.  
because I need that memory to other purpose. and any other way to save ram  
space?

Thanks  
Rajesh

On Friday, May 24, 2013 12:41:07 PM UTC+5:30, Adrien Grand wrote:

> Hi Raj,
> 
> How much memory did you give to the JVM? It's very common for JVMs to not  
> give back memory as soon as memory is not used anymore. They assume that if  
> memory was needed at some point, it might be needed again soon, so they  
> prefer keeping unused memory reserved instead of paying the cost to give  
> memory back to the OS and then allocate it again a few minutes later.
> 
> --  
> Adrien Grand

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)
#### Post date: [May 24, 2013, 10:30am UTC](https://discuss.elastic.co/t/memory-optimization/12109/4 "2013-05-24T10:30:13Z")

</div>

Hi,

On Fri, May 24, 2013 at 11:52 AM, raj [rajesh.elasticsearch@gmail.com](mailto:rajesh.elasticsearch@gmail.com)wrote:

> I have given 4GB memory to the JVM.  
> How can I free memory after deleting index.  
> because I need that memory to other purpose. and any other way to save ram  
> space?

Some JVMs such as the Oracle one support options to make the JVM give  
memory back to the OS more aggressively, see -XX:MaxHeapFreeRatio and  
-XX:MinHeapFreeRatio[1] for example (try lowering the default values).  
Please however note that this will bring a performance penalty since the  
JVM will need to perform more round-trips to the OS to allocate and release  
memory.

[1]

> **[Java HotSpot VM Options](https://www.oracle.com/java/technologies/javase/vmoptions-jsp.html)**
>
> This page contains HotSpot At a Glance related to Java SE.

--  
Adrien Grand

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Roy\_Russo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/roy_russo/32/44835_2.png) [@Roy\_Russo](https://discuss.elastic.co/u/Roy_Russo)
#### Post date: [May 24, 2013, 2:07pm UTC](https://discuss.elastic.co/t/memory-optimization/12109/5 "2013-05-24T14:07:50Z")

</div>

Well... how long has the memory been consumed? A GC (Garbage Collection)  
will be triggered depending on JVM options, like running out of permgen or  
oldgen. There is no harm in memory being consumed up to the limit set in  
the jvm options, so I wouldn't worry. If you run out of heap space, then  
worry.

On Friday, May 24, 2013 1:55:13 AM UTC-4, raj wrote:

> Hi,
> 
> I have a doubt. when I start Elasticsearch it's taking memory around  
> 510MB .now I created around 7,00,000 records in four indexes then it's  
> taking around 3.7GB memory.  
> but when i remove all four indexes memory it's not free.(means it does not  
> come to around 510MB).
> 
> My doubt is why Memory is not free after deleting the index.
> 
> Please help.
> 
> Thanks  
> Rajesh

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)
#### Post date: [May 25, 2013, 8:28am UTC](https://discuss.elastic.co/t/memory-optimization/12109/6 "2013-05-25T08:28:03Z")

</div>

How to you give 4GB to JVM? Please show your JVM options.

You must not use -Xmx and -Xms which is used by elasticsearch start  
scripts by default to enable the rare occasion of releasing heap memory  
back to OS. The heap is only one part of the memory in use and only the  
younger parts of the heap may be released back, which is very rare in  
long-running applications like ES.

The default strategy of ES memory is reserving the heap memory at once  
at startup time. It is most efficient to operate on already allocated  
memory with the vast amount of large objects on the ES heap. If you want  
to avoid ES memory strategy, ES performance will become a challenge  
because heap memory will immediately allocated again after having it  
released back to OS, just to continue other operations. All you will see  
is additional burden on the Java VM to handle memory requests.

Note, in the world of inverted indexing, assuming you can save memory by  
deleting an index is plain wrong. It's the dictionary (the list of  
unique terms in the documents and their frequencies) that dominates the  
volume of allocated space. You would have to delete all indexes to  
achieve memory saving. And a better method to delete all indexes is just  
not using ES.

Jörg

Am 24.05.13 11:52, schrieb raj:

> Hi,  
> Thanks for reply.  
> I have given 4GB memory to the JVM.  
> How can I free memory after deleting index.  
> because I need that memory to other purpose. and any other way to save  
> ram space?
> 
> Thanks  
> Rajesh
> 
> On Friday, May 24, 2013 12:41:07 PM UTC+5:30, Adrien Grand wrote:
> 
> ```
> Hi Raj,
> 
> How much memory did you give to the JVM? It's very common for JVMs
> to not give back memory as soon as memory is not used anymore.
> They assume that if memory was needed at some point, it might be
> needed again soon, so they prefer keeping unused memory reserved
> instead of paying the cost to give memory back to the OS and then
> allocate it again a few minutes later.
> 
> -- 
> Adrien Grand
> 
> ```
> 
> --  
> You received this message because you are subscribed to the Google  
> Groups "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send  
> an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:34am UTC](https://discuss.elastic.co/t/memory-optimization/12109/7 "2017-07-06T02:34:48Z")

</div>


