Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OutOfMemory Error java heap space

I'm using this statement

//some code
int a[][]=new int[5000000][5000000];
//some code

and running it with command

java -mx512m Test

It is giving OutOFMemoryError: Java Heap space indicating the line number of the mentioned statement in the stacktrace

How do i solve this problem

Edit: I'm trying to solve a practice problem on codechef

like image 584
Shwetanka Avatar asked Nov 22 '25 09:11

Shwetanka


1 Answers

You may need to consider an approach to your problem which requires less memory.

From Google Calculator (assuming a 64bit integer size):

(5 000 000^2) * 64 bits = 186 264.515 gigabytes
like image 143
pmalmsten Avatar answered Nov 24 '25 23:11

pmalmsten



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!