Patch Set 1:

The pack is normally closed when the last window to it is evicted from the WindowCache.

This eviction occurs one of two ways:

The first is by the weak LRU popping the least-recently-used window in order to release resources to keep the cache under the byte or open file limits. As these windows are popped the open window count on PackFile gets decreased, and the file is closed when the count drops to 0.

The second is when WindowCache spins the ReferenceQueue. If the JVM GC killed some of our SoftReferences in order to free up heap memory WindowCache will (eventually) spin those now dead references out and decrement the open window count on the associated PackFile. When the count drops to 0, the file is closed.

I just made a patch to C Git today that doesn't keep the file open if there is exactly 1 window on it. This might be useful in JGit too, but less so because the default window size is so much smaller (8 Kib in JGit). So it might not be worth my time to try and do.

Are you seeing file leaking or something Chris? This code is one of the most heavily exercised areas in Gerrit Code Review servers and the current version has been running in production pretty solidly for nearly 6 months.