There's an important memory leak in JSON-lib 2.2.2. It was said to be resolved in 2.4 but the fix is in appropriate.
In 2.2.2, using a ThreadLocal with cause OutOfMemory error under considerable user load under JBoss/Tomcat. A servlet of mine is using JSON-lib to serve JSON strings to a fair number of users. Since ThreadLocal is used, the HashSet instances remain in memory.
In 2.4, it's supposedly fixed. A SoftReference object is used but that's no better. Any soft-referenced object can be garbaged collected at anytime, even the once that are currently being used.
This is s JSON parse, it has no business dealing with neither threads nor nor garbage collection. Using a SoftReference object is also an anti-pattern. The calling code should not be put at risk in that manner.
Using static or pseudo-static objects is no good, Rather, the HashSet can simply passed around during the processing! Simpler and less risky. No ThreadLocal, no SoftReference.
Let me know if you need help refactoring this.
Best regards,
Patrice Gagnon
patrice@tenaya.ca
www.tenaya.ca
View and moderate all "bugs Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Bugs"