Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test for exercise 4.9 produces OutOfMemoryError #11

Open
lgtout opened this issue Nov 30, 2019 · 3 comments
Open

Test for exercise 4.9 produces OutOfMemoryError #11

lgtout opened this issue Nov 30, 2019 · 3 comments

Comments

@lgtout
Copy link

lgtout commented Nov 30, 2019

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

@jocelynlecomte
Copy link

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

@pysaumont
Copy link
Owner

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.

@lgtout
Copy link
Author

lgtout commented Jun 5, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants