fpinkotlin icon indicating copy to clipboard operation
fpinkotlin copied to clipboard

Test for exercise 4.9 produces OutOfMemoryError

Open lgtout opened this issue 5 years ago • 3 comments

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).

lgtout avatar Nov 30 '19 00:11 lgtout

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

jocelynlecomte avatar Jun 05 '20 13:06 jocelynlecomte

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 avatar Jun 05 '20 16:06 pysaumont

@pysaumont: Interesting. I didn't know that about array list. Thanks!

lgtout avatar Jun 05 '20 19:06 lgtout