void free ( boolean finalizer ) { // As free() may be called either by the finalizer or by FastThreadLocal.onRemoval(...) we need to ensure // we only call this one time. if ( freed . compareAndSet ( false , true ) ) { int numFreed = free ( tinySubPageDirectCaches , finalizer ) + free ( smallSubPageDirectCaches , finalizer ) + free ( normalDirectCaches , finalizer ) + free ( tinySubPageHeapCaches , finalizer ) + free ( smallSubPageHeapCaches , finalizer ) + free ( normalHeapCaches , finalizer ) ; if ( numFreed > 0 && logger . isDebugEnabled ( ) ) { logger . debug ( "Freed {} thread-local buffer(s) from thread: {}" , numFreed , Thread . currentThread ( ) . getName ( ) ) ; } if ( directArena != null ) { directArena . numThreadCaches . getAndDecrement ( ) ; } if ( heapArena != null ) { heapArena . numThreadCaches . getAndDecrement ( ) ; } } }
Should be called if the Thread that uses this cache is about to exist to release resources out of the cache