fpinkotlin
fpinkotlin copied to clipboard
Test for exercise 4.9 produces OutOfMemoryError
Exercise 4.9
I think the problem is that List is limited in size by the range of Int, whereas the test attempts to create a List whose size can be double the range of Int e.g. range(-2147483648, 2147483647)
.
You are right. The test which is in the solution
module is restricted to the first 500 integers. I just copied it to make it work, but it should definitely be reported by the author in the exercises modules
No. The OOME (OutOfMemoryError) is caused by the fact that there is not enough memory to create the list. It is not due to the maximal size of the list. The same error will occur if you try to create a list of Int.MAX_VALUE
elements, which is the maximum size that can be returned by the size
method of an array list.
But it is not the maximum number of elements an array list may contain. It could contain more if there was enough memory, but the size method would then return Int.MAX_VALUE
().
On my computer, the OOME happens after inserting 157 704 907 elements, when the maximum value for size
is 2 147 483 647.
I have fixed the problem with the test in module exercise.
@pysaumont: Interesting. I didn't know that about array list. Thanks!