# Why clear method in org.apache.lucene.search.LRUQueryCache not clear uniqueQueries

**URL:** <https://discuss.elastic.co/t/why-clear-method-in-org-apache-lucene-search-lruquerycache-not-clear-uniquequeries/57584>\
**Category:** Elasticsearch\
**Created:** [August 9, 2016, 10:41am UTC](https://discuss.elastic.co/t/why-clear-method-in-org-apache-lucene-search-lruquerycache-not-clear-uniquequeries/57584 "2016-08-09T10:41:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![makeyang](https://avatars.discourse-cdn.com/v4/letter/m/f05b48/32.png) [@makeyang](https://discuss.elastic.co/u/makeyang)\
**Post date:** [August 9, 2016, 10:41am UTC](https://discuss.elastic.co/t/why-clear-method-in-org-apache-lucene-search-lruquerycache-not-clear-uniquequeries/57584/1 "2016-08-09T10:41:58Z")

</div>

the method is below:  
public synchronized void clear() {  
this.cache.clear();  
this.mostRecentlyUsedQueries.clear();  
this.onClear();  
}

my question is: why not clear uniqueQueries?  
since I will make IndicesQueryCache dynamicly configurable I have to clear the previous one.  
but if LRUQueryCache's clear method not clear uniqueQueries, it could be memory leak.

---

<div class="post-metadata">

**Author:** ![mikemccand](https://avatars.discourse-cdn.com/v4/letter/m/f04885/32.png) [@mikemccand](https://discuss.elastic.co/u/mikemccand)\
**Post date:** [August 9, 2016, 6:21pm UTC](https://discuss.elastic.co/t/why-clear-method-in-org-apache-lucene-search-lruquerycache-not-clear-uniquequeries/57584/2 "2016-08-09T18:21:01Z")

</div>

Because `mostRecentlyUsedQueries` is actually just `uniqueQueries.keySet()` it means that clearing the former also clears the latter.

---

<div class="post-metadata">

**Author:** ![makeyang](https://avatars.discourse-cdn.com/v4/letter/m/f05b48/32.png) [@makeyang](https://discuss.elastic.co/u/makeyang)\
**Post date:** [August 10, 2016, 1:48am UTC](https://discuss.elastic.co/t/why-clear-method-in-org-apache-lucene-search-lruquerycache-not-clear-uniquequeries/57584/3 "2016-08-10T01:48:01Z")

</div>

> [@mikemccand](#):
>
> mostRecentlyUsedQueries

thanks very much.

---

<div class="post-metadata">

**Author:** ![mikemccand](https://avatars.discourse-cdn.com/v4/letter/m/f04885/32.png) [@mikemccand](https://discuss.elastic.co/u/mikemccand)\
**Post date:** [August 10, 2016, 9:11am UTC](https://discuss.elastic.co/t/why-clear-method-in-org-apache-lucene-search-lruquerycache-not-clear-uniquequeries/57584/4 "2016-08-10T09:11:34Z")

</div>

Thank you for asking about it, it indeed looks at first like it might be a memory leak.

I pushed a comment to Lucene's sources to help clarify:

> <https://github.com/apache/lucene-solr/commit/3816a0eb2bbd1929523ae27db3c90d0942ed5f5f>

---

<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 5, 2017, 10:28pm UTC](https://discuss.elastic.co/t/why-clear-method-in-org-apache-lucene-search-lruquerycache-not-clear-uniquequeries/57584/5 "2017-07-05T22:28:51Z")

</div>


