java
java copied to clipboard
JsonStreamPool cached JsonStream instances are never eligible for GC
JsonStream.serialize(...) methods use intern ThreadLocal JsonStream instances from JsonStreamPool which are never issued for GC unless the thread ends. This leads to much higher memory footprint for web applications ( which use thread pools ) where, let say 99% of JSON responses are small (under 300k) and the rest 1% are comparatively much bigger (e.g. 1-2 MB).
It would be convenient to have some configurable limit (e.g. JsonStream size in bytes) which if exceeded, borrowed JsonStream instance isn't returned to the pool.
(Currently we have to use a workaround that borrows (and never returns) JsonStream instance from the JsonStreamPool after serialization, if resulting OutputStream size exceeds some limit)