In order to reduce GC pauses in Java, I want to recycle objects of a particular class, to the best of my knowledge this can be done by using io.netty.util.Recycler. Unfortunately using io.netty.util.Recycler you need to call recycle each time the object is no longer referenced and in my case objects of this class are passed around throughout the code and it is difficult to keep track of where their life span ends and it makes the code quite ugly.
Does anyone know of a better method to recycle objects in Java, without having to keep track of where the objects are no longer referenced?
Project:- https://github.com/yahoo/pulsar
Class I want to recycle:- https://github.com/yahoo/pulsar/blob/master/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/PositionImpl.java