ppkarwasz opened a new pull request, #804:
URL: https://github.com/apache/commons-io/pull/804

   Commit 0698bd9eafb2d20fb85f4ea4f695db1b702dcef2 introduced convenient 
`AutoCloseable` usage for `ScratchBytes` and `ScratchChars`. However, it also 
introduced a **classloader memory leak risk** in application server 
environments by storing custom wrapper instances directly in a `ThreadLocal`.
   
   This PR keeps the ergonomic `AutoCloseable` pattern while eliminating the 
classloader leak risk:
   
   * Store **only primitive buffers** (`byte[]` / `char[]`) in the 
`ThreadLocal`, not custom classes.
   * Introduce two types of `ScratchBytes` / `ScratchChars` instances:
   
     * **Global instance** (`buffer == null`) that fetches its buffer from the 
`ThreadLocal`.
     * **Reentrant instances** (`buffer != null`) for nested usage without 
interfering with shared buffers.
   
   **Note:** While this revision keeps the readability of using the 
`AutoCloseable` API, it also introduces a performance regression compared to 
the original #801 design: retrieving a buffer now requires two `ThreadLocal` 
lookups: once in `get()` and once in `array()`. The original design avoided 
this overhead intentionally. Since these classes are package-private and used 
in performance-sensitive paths, we should carefully weigh the trade-off between 
API convenience and runtime cost.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to