Leo Vo
Leo Vo

Reputation: 10330

OutOfMemoryException - how to find memory leak?

I am developing a WinForm application. When running it for a long time wihout stopping, it suddenly raise a OutOfMemoryException. I don't know how to find the reason which causes this exception. I use Task Manager to see how much memory my application to use, I see that it only take 90000 KB while my RAM is 2GB. I don't know it is a memory leak error? If yes, I remember there are some .NET tools to help finding the memory leak.

Please help me. Thanks.

Upvotes: 3

Views: 1595

Answers (2)

DurhamG
DurhamG

Reputation: 222

vmmap

A useful tool to see how much and what kind memory your process is using.

CLR Profiler

Provides a graphical view of the heap and what is holding on to what. It can be a bit slow, but if the leak is in the managed heap it will point out what types are the problem pretty easily. Here's a guide.

WinDBG

Like parapura mentioned, this is will let you find your leak, but there's a steep learning curve (and almost no gui).

Upvotes: 1

parapura rajkumar
parapura rajkumar

Reputation: 24403

If you run your application through WinDbg you will be able to get a break down of all the objects in memory. A unusually large number will pin point the exact object that is causing this behavior.

You can follow these instructions

In a nut shell you do

  1. Attach WinDbg to process
  2. Issue .load SOS.dll command
  3. Issue !dumpheap –stat to view managed objects

Upvotes: 4

Related Questions