Lists of Integer, Long, execute ok. However when using String the code below consumes over 5GB of memory when an entry at most should be in the neighborhood of 8 bytes per String, equating to only ~700MB. It also runs infinitely never throwing heap out of bounds. What is going on?
List<List<String>> arrayList = new ArrayList<List<String>>();
long offset = 1000;
long size = 83886080;
int max = Integer.MAX_VALUE - 100;
long subloops = 1;
if(size > max)
{
subloops = size / max;
}
int temp = 0;
long count = 1;
long start = System.nanoTime();
for(int j=0; j<subloops; j++)
{
temp = (int)(size % max);
arrayList.add(new ArrayList<String>(temp));
List<String> holder = arrayList.get(j);
for (long i = 0; i < temp; i++)
{
holder.add(Long.toString(offset + count));
count++;
}
size -= temp;
}
long finalTime = System.nanoTime() - start;
System.out.println("Total time = " + finalTime);
System.out.println(count);
//for reference the max item length in bytes ends up being 8
System.out.println(Long.toString(offset+count).getBytes().length);