I am trying to parse a csv file to a pojo. To do this I am using jackson-dataformat-csv. I am testing the scalablity of my program and while time does not seem to be an issue the memory it uses is. I am using just over a million records in a csv to parse into my pojos. The problem is the server that will have this running on will have about 1.5GB ram and so far I have found that it is using almost 2GB at just over a million records. My problem is when I use this:
MappingIterator<T> objects = csvMapper.readerFor(pojoClass).with(csvSchema).readValues(csvFile);
List<T> list = objects.readAll();
the list I get back is almost 2GB. When I create a list of a million pojos I use almost no memory. I am creating that list like this:
List<Pojo> pojos = new ArrayList<>();
for(int i = 0; i < 1000000; i++){
Pojo newPojo= getNewPojo();
pojos.add(newPojo);
}
I am not sure why the first list I get back is so large when I can create a different list with the same number of objects just a different way of putting them there and have that list so small. Please let me know if I am doing something wrong and how I can fix this issue I am having. Thanks.