Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ThreadLocal usage in JsonFactory may cause memory leaks #189

Closed
soldierkam opened this issue Apr 13, 2015 · 5 comments
Closed

ThreadLocal usage in JsonFactory may cause memory leaks #189

soldierkam opened this issue Apr 13, 2015 · 5 comments
Milestone

Comments

@soldierkam
Copy link

JsonFactory assign BufferRecycler to thread local but does not remove it. Very often jackson-core is loaded by web application classloader so we have situation where this classloader is referenced from thread object. As a result, after undeploying web app, classes wouldn't be unloaded (or wil be unloaded after some time because of the SoftReference).

@cowtowncoder
Copy link
Member

Right, SoftReference is intended as the mechanism for removing the dependency.
Reuse of buffers is a significant performance improvement for common usage, so I do not want to remove functionality itself.
But I am open to improvement ideas.

One possibility I could consider is adding a JsonFactory.Feature that would allow disabling this recycling. If this makes sense, it could be added in 2.6.

@cowtowncoder
Copy link
Member

Actually, even if class eviction is delayed a bit, how big of a problem should this be? BufferRecycler only refers to native JDK types (byte and char arrays) and has no references to other Jackson classes.
So at most it would seem like it'd be able to retain BufferRecycler class and nothing else?

@cowtowncoder cowtowncoder added this to the 2.6.0 milestone Apr 24, 2015
@cowtowncoder
Copy link
Member

Added JsonFactory.Feature.USE_THREAD_LOCAL_FOR_BUFFER_RECYCLING, disabling of which will prevent recycling of BufferRecycler. Note that doing this is likely to have negative performance impact, especially for reading/writing small json documents.

@JasonHuangHuster
Copy link

Hi , i found my java server had frequent full gc these days .

  1. i 've dump the heap ( jmap -histo:live) and found lots of char array objects in the memory (the whole live heap is 500M and char[] objects is 60% of it, that's 300M)
  2. then i checked some char[] objects , they're json datas i put on zookeeper which is parsed by Jackson . and those objects are refferenced by ThreadLocal , and the content inside is the same . my server had 500 threads ,so the total char[] is quite a big usage .

IMHO , those json file are read only in my server, so singleton instance of each is fit in my case .
would you give me some tips for how to dealing with this ? tks advance ! 😃

@cowtowncoder
Copy link
Member

@JasonHuangHuster for questions please use mailing lists; this is a closed issue.

As to memory usage, SoftReferences are automatically reclaimed by GCs, and not just OldGen ones so I don't think this usage is related.
jmap would include soft-reachable values but that doesn't tell much: they get evicted if there is any memory pressue.

But if you think it could help, try disabling JsonFactory.Feature.USE_THREAD_LOCAL_FOR_BUFFER_RECYCLING on JsonFactory used (and construct ObjectMapper with factory configured this way).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants