Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.


#124 memory leak in 2.2.2, not fixed correctly in 2.4


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


  • Anonymous

    • priority: 5 --> 9
    • assigned_to: nobody --> aalmiray
    • summary: memory leak in 2.2.2, not fixed correct in 2.4 --> memory leak in 2.2.2, not fixed correctly in 2.4