Hello.
First of all, sorry for a long introduction, but I believe that it may be relevant.
We have a J2EE application that does a lot of JSON processing, for both serializing and deserializing JSON objects. We are using 2.2.3 version of google-gson to do the job. Each individual application node may process high number of requests (up to 1000/second). We had no problems with any of this until today.
Analyzing the heap dump that I got from one of the VMs, after it had reached such a state, with Eclipse Memory Analyzer, I could see that about 1.9Gb of heap was occupied by unreachable objects. Now, while I'm dealing with that fact separately, the contents of these unreachable object pile are concerning on their own. To list the top occupants in quantity/space/class:
25M/804M/com.google.gson.internal.StringMap$LinkedEntry
19M/206M/com.google.gson.JsonPrimitive
5M/219M/com.google.gson.internal.StringMap
5M/199M/com.google.gson.internal.StringMap$LinkedEntry[]
9M/141M/java.lang.Integer
4M/73M/com.google.gson.JsonObject
The list goes on, there are a lot of reflection instances, etc. Going down, the first time I see instances of my bean, is at 11K objects. For this particular instances, I estimate that per each request, a maximum of 30 of them can be created. That tells me that per each request, there are 70K of StrngMap$LinkedEntry instances created (for example).
Unfortunately, I didn't include unreachable classes into the analysis, so I can only get the list, and not the origins.
All my GSon instances are static (have made this mistake before).
Here is what I've done as a test (attached). I took sample JSON, like the one we would produce in production, and simply deserialized it and serialized it back, into a map based object. I ran this operation on a single VM, only once, and took the heap dump after the operation. I then used MAT again to list the unreachable objects. Here is what I see after that single run (no. instances / class):
3,844 com.google.gson.internal.StringMap$LinkedEntry
2,924 com.google.json.JsonPrimitive
1,038 com.google.gson.internal.StringMap$LinkedEntry[]
710 com.google.gson.internal.StringMap
The numbers do seem to be quite high, even for an object of such a complexity.
Thank you,
Pawel.