I'm experiencing an odd behavior in a project I'm currently working on. What I'm seeing is that when I reference an InternalSearchHit.sourceAsMap directly I'm experiencing a memory leak. The code is doing some graph traversal and so there are references to other InternalSearchHit.sourceAsMap documents as well.
I'm currently writing groovy code, and so part of what I'm seeing is:
def docMap = hit.sourceAsMap() //Add data into hash map //Add other InternalSearchHit.sourceAsMap as child of map
I end up with a memory leak.
If I copy the map using the HashMap constructor:
def docMap = new HashMap(hit.sourceAsMap()) //Add data into hash map //Add other InternalSearchHit.sourceAsMap as child of map
Then the memory leak goes away.
I took a look at the source for InternalSearchHit and I didn't see anything glaring. At best what I can guess, is that referencing the sourceAsMap object retains a hold on the SearchHit which in turn retains a hold on something else.