Is calling BufferRecyclers.releaseBuffers() no longer necessary on contextDestroy?
danshome opened this issue · 5 comments
Search before asking
- I searched in the issues and found nothing similar.
Describe the bug
We had to add a call to BufferRecyclers.releaseBuffers(); in our contextDestroy method to avoid a memory leak on hot redeploy, but after upgrading to the 2.16.1 we are getting a message that BufferRecyclers is deprecated. Is calling BufferRecyclers.releaseBuffers() no longer necessary?
Version Information
2.16.1
Reproduction
<-- Any of the following
- Brief code sample/snippet: include here in preformatted/code section
- Longer example stored somewhere else (diff repo, snippet), add a link
- Textual explanation: include here
-->
// Your code here
Expected behavior
No response
Additional context
No response
Deprecated does not mean they work differently (yet). We have not deprecated the releaseBuffers method (yet). In a future version of jackson-core, the buffer recycling will default to the new buffer recycling code but it still defaults to the old code right now.
Ok the short answer is that if you needed this functionality before, you can keep on using it. Method will not be removed before 3.0.
But ideally no one should ever (have to) call BufferRecyclers.releaseBuffers()
-- it only has effect for esoteric case of System property com.fasterxml.jackson.core.util.BufferRecyclers.trackReusableBuffers
being enabled.
So unless you set that sysprop, method does absolutely nothing; I assume you were aware of this but I just mention it for sake of completeness.
This system will be removed from Jackson 3.0, and if anyone needs something similar, that would indeed need to be implemented using new (in 2.16) RecyclerPool
API.
But the need for tracking and release only concerns the default ThreadLocal
-based recycling so eventually, even with 2.x (we hope), we hope to change default buffer recycling scheme to use pools that are bound to JsonFactory
instances.
With that, buffers should not be problematic wrt context reloading.
Apologies for bit of stream-of-consciousness explanation here.
Also, TL;DNR:
Yes, with 2.16 and later, use of different RecyclerPool
(like any of alternatives included) will remove need to use BufferRecyclers.releaseBuffers()
. But if leaving current default implementation, ThreadLocal
-based one, it may still be used as before for same reasons it was already used. And while deprecated, mechanism WILL NOT be removed from Jackson 2.x.
Also, wrong repo; will move to jackson-core
where relevant functionality lives.
Created #1202 which should remove need for BufferRecyclers.releaseBuffers()
, when using one of newer pool implementations. Closing.