views:

242

answers:

5

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

+3  A: 

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.

Brian Agnew
@Brian Agnew hey, i already tried to increase the JVM memory..Do you have maybe another advise?
or.nomore
Have you tried profiling it ?
Brian Agnew
@Brian Agnew sorry for my ignorance, what is profiling?
or.nomore
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
A: 

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

While(condition){

    String s="tttt";

}

This should be avoided as it waste lot of memory.

Shashank T
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
Thanks a lot..this is something i wasn't not knowing.It really makes my day.
Shashank T
A: 

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.

gustafc
A: 

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.

Ryan Fernandes