I am currently in the process of analyzing code quality for a controller method, that has quiet a few ArrayLists initializations as follows:
public controller(Aggregate agr) {
List<FCompound> fCompounds = new ArrayList<>();
List<CCompound> cCompounds = new ArrayList<>();
List<Dist> oDist = new ArrayList<>();
List<Trans> oTrans = new ArrayList<>();
List<CContent> cContents = new ArrayList<>();
List<FDist> fDidst = new ArrayList<>();
List<CDist> cDist = new ArrayList<>();
List<FDist> efDist = new ArrayList<>();
List<CDist> ecdist = new ArrayList<>();
List<KList> kList = new ArrayList<>();
which are actually invariable getting assigned to different ArrayList Objects through Lists returned by DB Services
List<FCompound> fCompounds = DBservice().getAllfCompounds();
List<CCompound> cCompounds = DBservice().getAllcCompounds();
List<Dist> oDist = DBservice().getODist();
List<Trans> oTrans = DBservice().getOTrance();
List<CContent> cContents = DBservice().cContent();
List<FDist> fDidst = DBservice().getFDist();
List<CDist> cDist = DBservice().getcDist();
List<FDist> efDist = DBservice().getefDist();
List<CDist> ecdist = DBservice().getecDist();
List<KList> kList = DBservice().getKDist();
}
almost immediately meaning all ArrayList Objects created in the first code snippet are Toast for garbage collection
The issue at first place is that this Controller method is invoked for every request due to a poor design of the 1 monolithic controller which serves 100% of the application traffic, now I am starting to doubt if this is gonna start causing Memory leaks due to less heap space?
What would be a workaround for this problem, would initializing the lists with null as
List<FCompound> fCompounds = null;
or it wouldn't change anything?
is there a way to analyze the heap space through a stress test for this method?