1

Possible Duplicate:
General strategy to resolve Java memory leak?

I have a standalone program that I run locally, Recently I found that it has a memory leak, right now our only solution is to restart it every day. What is the best way to go about finding this memory leak? Which tool and method should we use?

thanks in advance

Community
  • 1
  • 1
Selva
  • 839
  • 10
  • 25
  • 40

1 Answers1

2

Profilers are usually helpful in finding memory leaks in complex programs. But if the program in question is small, you can try to find the memory leaks by carefully reading through the source code.

Think about following questions while you are reading the source code:

  1. What action is your program doing repeatedly? What objects are being created during this actions?
  2. Which of the created objects are needed by the program after the action is completed?
  3. Which objects are created once (for example at program startup) and remain in the memory till the end?
  4. Do any of the objects identified in earlier steps are reachable from the objects identified in step #3. If you find that some objects that are discard-able are reachable from objects from step #3 think about how can you break this reachability.
Tahir Akhtar
  • 11,385
  • 7
  • 42
  • 69