Thanks for the pointer Alan. I can see that proposal is more mature than my suggestion and I will defer to that.
On Wednesday, May 20th, 2026 at 14:16, Alan Bateman <[email protected]> wrote: > > > On 20/05/2026 19:04, Charles Connell wrote: > > Hello, > > > > I am a long-time Java user. In my daily work, I encountered a Java > > application that had a native memory leak, but Native Memory Tracking was > > not helpful in exposing it. I eventually discovered the problem was > > unclosed GZipInputStreams. Each of the GZipInputStream objects had > > corresponding allocations made by zlib, and these were being leaked. > > > > I propose to wire Native Memory Tracking into Deflater+Inflater+zlib. The > > details could include: > > - Add a new memory tag category "zlib" > > - ZipLibrary class passes pointers to os::malloc and os::free wrappers into > > libzip upon initialization (this might be the tricky part) > > - Inflater and Deflater use alloc and free wrappers instead of libc when > > they memory > > - When allocating a z_stream, Inflator and Deflater set the zalloc and > > zfree pointers to our wrapper functions. This takes advantage of an > > existing zlib feature that allows us to provide custom alloc and free > > functions. No changes to zlib itself are required. > > > > I am confident that many programmers forget to close their > > GZIP[Input|Output]Streams, and this enhancement could be a help to them. > > This is interest is extending NMT to the native allocations and native > memory managed by the JDK core libraries. Johan Sjölén has submitted a > JEP [1] to add the infrastructure and internal APIs needed to support this. > > -Alan > > [1] https://openjdk.org/jeps/8354416 >
