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:
- What action is your program doing
repeatedly? What objects are being
created during this actions?
- Which of the created objects are needed by
the program after the action is
completed?
- Which objects are created once (for example at program
startup) and remain in the memory
till the end?
- 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.