Tonyl1980 commented on PR #804: URL: https://github.com/apache/commons-io/pull/804#issuecomment-3418830243
Please no file editing or switchbacks to generic. Please release editing of my account or device. Thank you. On Sat, Oct 18, 2025, 5:25 PM Piotr P. Karwasz ***@***.***> wrote: > Commit 0698bd9 > <https://github.com/apache/commons-io/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 <https://github.com/apache/commons-io/pull/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. > ------------------------------ > You can view, comment on, or merge this pull request online at: > > https://github.com/apache/commons-io/pull/804 > Commit Summary > > - 9b5b5b3 > <https://github.com/apache/commons-io/pull/804/commits/9b5b5b393f5085d9ec24154e01e06e69d0bbd956> > Prevent classloader memory leak in `ScratchBytes`/`ScratchChars` > > File Changes > > (1 file <https://github.com/apache/commons-io/pull/804/files>) > > - *M* src/main/java/org/apache/commons/io/IOUtils.java > <https://github.com/apache/commons-io/pull/804/files#diff-b106f51e7daf5b40ed10dccc4622f425f3e82afc52fb736547a8f28efa6478e4> > (34) > > Patch Links: > > - https://github.com/apache/commons-io/pull/804.patch > - https://github.com/apache/commons-io/pull/804.diff > > — > Reply to this email directly, view it on GitHub > <https://github.com/apache/commons-io/pull/804>, or unsubscribe > <https://github.com/notifications/unsubscribe-auth/BR6O56BPARMKU5YSQY6GO633YKV4LAVCNFSM6AAAAACJSJJVLSVHI2DSMVQWIX3LMV43ASLTON2WKOZTGUZDSMRRGU4DANY> > . > You are receiving this because you are subscribed to this thread.Message > ID: ***@***.***> > -- 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]
