High RAM usage when creating a large csv histogram

in my simulation I create a 3D histogram of about 1000 x 1000 x 20 = 2e7 bins. When saved at the end, it takes about 350 MB. However, during the simulation the RAM usage increases by about 120 GB (for 50 threads) in comparison to the case when no histogram is created. It makes up 2.4 GB / thread. Why is it so much bigger than the size of the saved histogram and is there a way to make RAM usage lower?
Thanks in advance.