I would like to better understand what Java memory management performs in the following situation.
Knowing that I am suffering from performance problems, I am trying to take the utmost care not to make the situation even worse, it was necessary to perform the following method:
public List<List<Object>> getValues() throws DataNotFoundException {
List<List<Object>> values = new ArrayList<>();
for (SurveyActivity surveyActivity : this.surveyActivities) {
this.recordsFactory = new SurveyActivityExtractionRecordsFactory(this.surveyForm, this.headersFactory.getHeaders());
List<Object> resultInformation = new ArrayList<>();
this.recordsFactory.getSurveyBasicInfo(surveyActivity);
this.recordsFactory.getSurveyQuestionInfo(surveyActivity);
resultInformation.addAll(new ArrayList<>(this.recordsFactory.getSurveyInformation().values()));
values.add(resultInformation);
}
return values;
}
Notice that the recordsFactory
attribute is getting a new instance for each entry in the loop, this decision-making is due, since we need to "clean" the instance of the object for each entry in the loop, such as the Java memory manager will you handle this situation?
Will it allocate this new object in the same memory space previously?
Knowing that I need to "clean" this instance, is there a better alternative?
Is there an article where I can find more information about how the memory manager works?