5

My application is a web socket client that continuously parses JSon using Jackson 2.9.4. I am experiencing a memory leak with SoftReferences in Thread Local not being cleared.

I have configured Jackson to NOT use a Thread Local as follows:

JsonFactory factory = new JsonFactory();
factory = factory.disable(JsonFactory.Feature.USE_THREAD_LOCAL_FOR_BUFFER_RECYCLING);
objectMapper = new ObjectMapper(factory);

But despite this setting, I keep seeing increases in char[] referenced by BufferRecycler:

enter image description here

This takes up around 40% of the physical memory and keeps growing, regardless of memory pressure, until I run out of physical memory.

  1. How can I disable the use of Thread Local by Jackson?
  2. What causes this BufferRecycler reference to be kept in memory?

Thanks,

Stik

stikkos
  • 1,916
  • 2
  • 19
  • 34
  • if you could post the all around context for the mapper usage. Are you reopening the factory each time ? Is the converted object being directly flushed to some connector , or you simply keep it up in RAM ? Also you notice this behavior in both serialization and de-serialization and also for all type of messages ? Or you have a pretty-complex data model that keeps hard `Map<>` in it – AntJavaDev Feb 22 '18 at 08:18
  • I use a static Object Mapper, shared by all Threads (as suggested [here](https://github.com/FasterXML/jackson-docs/wiki/Presentation:-Jackson-Performance)), which is initialised with the factory shown above. The converted object is a simple POJO (no complex Maps) and passed to a different server so not kept in memory. Since I'm consuming a websocket, It's happening on de-serialization. – stikkos Feb 22 '18 at 08:39
  • hmm cannot be sure but it could also mean that AKKA is keeping the `Byte[]` due to the web socket sessions. Have you tried terminating the Web Sockets sessions ? If you close the channel , is the stream still kept in RAM? – AntJavaDev Feb 22 '18 at 09:19
  • I did think about that and build in a hard disconnect every hour but this had no impact on the leak. It looks like the only reference is the soft reference but I don't understand why it's not being GCd – stikkos Feb 22 '18 at 09:30
  • is it hard to change the layer that you do the de-serialization ? Try changing it with a simple Jersey Client and also make it Stateless , do not reuse the client instance – AntJavaDev Feb 22 '18 at 10:07

0 Answers0