Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception in thread "main" java.lang.OutOfMemoryError, How to find and fix? [duplicate]

I'm trying to programming a crossword creator. using a given dictionary txt file and a given pattern txt file. The basic idea is using DFS algorithm. the problem begin when the dictionary file is v-e-r-y big (about 50000 words). then i recive the :

Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded

i know that there is a part in my program that wastes memory, but i don't know where it is, how to find it and how to fix it

like image 867
or.nomore Avatar asked Sep 11 '25 06:09

or.nomore


2 Answers

Does it really waste memory ? If you're loading a sizeable dictionary, then you may simply want to increase the JVM memory settings (the JVM has a maximum memory allocation - dependent on your platform, and configurable).

e.g.

$ java -Xmx512m ....

would increase the maximum memory allocation of the JVM to 512m.

If you think you have a memory leak (garbage collection not kicking in due to references not being released) then a profiler such as YourKit may be of use. Note that this isn't free, but the trial version may help you solve your problem.

like image 166
Brian Agnew Avatar answered Sep 12 '25 21:09

Brian Agnew


To solve this problem ( in linux based os ) do following

1) increase memory (so that this problem don't come frequently ) by configuring "domain.xml" in

/glassfish/domain/domain1/config

search for

<jvm-options>-XX:MaxPermSize=

set it to higher value eg- 198m or 256m

2) kill the glassfish process to free the port on which it was running ( in my case it was 8686) open terminal (in linux based os) and type -

sudo netstat -npl | grep 8686

this will result in something like..

tcp6 0 0 :::8686 :::* LISTEN 3452/java

next use

kill -9 3452 to kill that process ( 3452 in this case )

Now try to start glassfish, it should start.

like image 39
vkantiya Avatar answered Sep 12 '25 21:09

vkantiya