I
I
ideas4ru2011-12-14 10:46:07
Java
ideas4ru, 2011-12-14 10:46:07

Memory issues in Java?

It all started with the fact that the program began to crash when allocating memory, so I began to understand and added logging to the code.
rows and cols are 84 each.

writeLog(&quot;total &quot; + Runtime.getRuntime().totalMemory() + &quot; max &quot; + Runtime.getRuntime().maxMemory() + &quot; free &quot; + Runtime.getRuntime().freeMemory());<br/>
<br/>
costMatrix = new byte[rows][cols][rows][cols];<br/>
writeLog(&quot;costMatrix allocated&quot;);<br/>
<br/>
writeLog(&quot;total &quot; + Runtime.getRuntime().totalMemory() + &quot; max &quot; + Runtime.getRuntime().maxMemory() + &quot; free &quot; + Runtime.getRuntime().freeMemory());<br/>
<br/>
directionMatrix = new Aim[rows][cols][rows][cols];<br/>
writeLog(&quot;directionMatrix allocated&quot;);<br/>
<br/>

The result
is total 16318464 max 259522560 free 15968416
costMatrix allocated
total 73519104 max 259522560 free 13535792
1. Firstly, very strange numbers 16 against 73 MB of occupied memory, but the free memory has practically not changed.
2. directionMatrix allocated does not appear in the log. Tried to catch the exception, but it doesn't catch.
PS I added -Xms2g -Xmx2g options for the virtual machine, but it still doesn't help.
I would be grateful for any information on the topic. Newbie in Java.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
1
1nd1go, 2011-12-14
@1nd1go

There is such a jvisualvm tool, it lies in $java_home$/bin.
Allows you to monitor exactly how memory is allocated. There is a detailed instruction for it on the oracle website, googled for visualvm.

A
anmipo, 2011-12-14
@anmipo

1. What is the Aim class? If each instance takes up more than ~40 bytes, it's not surprising that an 84^4 array won't fit in 2 GB.
2. What exception did you try to catch? OutOfMemoryException (which happens for various reasons ) is not a descendant of java.lang.Exception.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question