Each time you add a single item to the array, you allocate a whole new array. So it's a factorial sequence. Do it 10,000 times from 0 - 10k and the memory allocated along the way is 7GB. Of course each iteration the previous array is available for garbage collection and is collected, but there you go - the effort of garbage collecting and allocating new space isn't free etc! It can also easily lead to memory fragmentation which requires more complex GC.
Hi thanks for the explanation! I would love to know more about how you can profile the memory allocation to quantitatively analyze the performance problem. Are there any good resources on this?
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Each time you add a single item to the array, you allocate a whole new array. So it's a factorial sequence. Do it 10,000 times from 0 - 10k and the memory allocated along the way is 7GB. Of course each iteration the previous array is available for garbage collection and is collected, but there you go - the effort of garbage collecting and allocating new space isn't free etc! It can also easily lead to memory fragmentation which requires more complex GC.
Hi thanks for the explanation! I would love to know more about how you can profile the memory allocation to quantitatively analyze the performance problem. Are there any good resources on this?