Take the 2-minute tour ×

This question already has an answer here:

hey, 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

share|improve this question

marked as duplicate by ThiefMaster Mar 18 '13 at 23:11


"How to find" is covered by this related question: stackoverflow.com/questions/2840421/… –  meriton Jun 6 '10 at 21:26

5 Answers 5

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


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

share|improve this answer
hey, i already tried to increase the JVM memory.. Do you have maybe another advise? –  or.nomore Jun 6 '10 at 17:48
Have you tried profiling it ? –  Brian Agnew Jun 6 '10 at 17:54
sorry for my ignorance, what is profiling? –  or.nomore Jun 6 '10 at 18:18
Running the program with some sort of tool (e.g. YourKit) and getting statistics/metrics out such that you can determine where the bottlenecks (e.g. memory consumption) are. –  Brian Agnew Jun 6 '10 at 18:28

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


search for


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.

share|improve this answer

Some Times, I have seen people initialize variables in loop like


    String s="tttt";


This should be avoided as it waste lot of memory.

share|improve this answer
It doesn't necessarily waste memory (and your example definitely doesn't, as string literals are pooled). It can even help as garbage collection of young objects is cheaper than collecting old objects. –  gustafc Jun 6 '10 at 18:35
Thanks a lot..this is something i wasn't not knowing.It really makes my day. –  Shashank T Jun 6 '10 at 18:49

This is a tricky problem. I've run into it once or twice, and increasing heap size doesn't help. Solving it with VM settings - you may even want to decrease the heap size (it once worked for me). You may also want to test different garbage collectors, I've had success using the G1 collector.

General advice on how to avoid this error is also hard (or so it seemed to me when I researched this matter to solve my own problems). High infant mortality is probably good, since young objects are cheaper to collect than old ones.

share|improve this answer

large dictionary...mmm.. is there an absolute requirement of storing that directly in the memory of the jvm?

A lazy chap like myself would store this in a database (in-memory even perhaps? - hypersonic for example), transfer the responsibility of searching through a list to the database while my program worked on creating interesting symmetric black and white square combinations :)

Just a thought though.

share|improve this answer
