Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8472609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:07:24+00:00 2026-06-10T17:07:24+00:00

In order to track down memory leaks, I have been using Visual Studio and

  • 0

In order to track down memory leaks, I have been using Visual Studio and SOS.dll to provide dumps of the object heap, and to see what is GCRooting a particular object in place.

I started automating this process using AutoIt to control my mouse and keyboard. Here is an approximation of the first part of my script:

In Visual Studio, press F5 to start execution
Let the program fully load
Switch to Visual Studio and break execution

Switch focus to the immediate window
Load SOS.dll
Call !dumpheap -stat
Copy the result of the dump to the clipboard
Paste in notepad and save as dump1.txt

Resume execution
Perform the leaky action a number of times
Switch to Visual Studio and break execution

Switch focus to the immediate window
Clear the output
Call !dumpheap -stat
Copy the result of the dump to the clipboard
Paste in notepad and save as dump2.txt

Run a Python script which compares the two dumps and locates leaked objects

I have a few concerns with my current method, though. Not only am I dependent on an installation of Visual Studio, but while the script is running I cannot use the mouse or keyboard without throwing the automation out of sequence.

Is there a way to use SOS.dll within a C# program rather than Visual Studio? Ideally this solution would attach to a specified process and output the result of !dumpheap -stat to a text file without the need for automating Visual Studio.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T17:07:26+00:00Added an answer on June 10, 2026 at 5:07 pm

    Below I will present some different approaches you can use to find your leaks.

    (there are commercial “leak” detectors available should you not wish to follow the DIY approach).

    Link to my answer detailing lots of debugging tools/resources

    • How to use WinDbg to analyze the crash dump for VC++ application?

    Load SOS.DLL into WinDBG

    You actually don’t need Visual Studio to use SOS.DLL….it’s a debugger extension so can be used in WinDBG too.

    You can get the WinDBG Debugger free as part of the Debugging Tools for Windows.

    You could then write a WinDBG script to automate your “dumps”.

    Also be aware, there are enhanced versions of SOS.DLL available…look for SOSEX, PSSCOR2 (for NET 2), and PSSCOR4 (for NET 4).

    CLR Profiling API

    You can use the CLR Profiling API.

    There’s an application called CLRProfiler which is an actual .NET profiler that makes use of it….so a good bit of code to see how it’s used.

    One of the things CLR Profiler can do is allow heap dumps to be made and then compare those dumps made at different time periods, to find the differences…and thus help find leaks.

    You could provide similar functionality to your application when in a “test” mode (either embedded in the application, or as a companion utility to monitor it).

    • http://msdn.microsoft.com/en-us/magazine/cc300553.aspx

    • http://www.microsoft.com/en-gb/download/details.aspx?id=16273

    • http://blogs.msdn.com/b/davbr/

    Process Dumps

    Another technique you can use is to take periodic “dumps” of your process, which you can then analyze offline via WinDBG with SOS/SOSEX (or any other WinDBG plugin).

    You can use DebugDiag (you can set up rules and actions to control when .dmp files are created) to automate the creation of .dmp files….or a tool called ProcDump.exe (from SysInternals).

    • http://www.microsoft.com/en-us/download/details.aspx?id=26798

    • http://technet.microsoft.com/en-us/sysinternals/dd996900.aspx

    ProcDump is particularly useful because it is able to take the “process snapshot” very quickly because it uses a technique called “Process Reflection”….this enables your process to be interrupted less aggressively e.g.

    (create 3 dumps with 5 seconds gap between each one)

    procdump -s 5 -n 3 notepad.exe notepad.dmp 
    

    Post-Mortem Analysis

    After you have a set of .dmp files you can then analyze them to find leaks, monitor handle usage, etc.

    You can manually load the .dmp files in WinDBG and then issue debugger commands, or you could write a WinDBG extension or maybe a script which took the set of dump files and processed them in turn (i.e. ran the !dumpheap stat command on them).

    Debug Analyzer .NET

    • http://www.debuganalyzer.net/

    This is a tool aimed at analyzing .dmp files and doing post-mortem analysis.

    It lets you write scripts in .NET so is maybe more accessible than WinDBG.

    It also has a plugin model if you want to extend it.

    And it lets your write/use Visualizers to view the data in unique ways.

    (currently only supports CLR 2.0 memory dumps…not CLR 4.0)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

first question, hoping someone can help here. I've been trying to track down how
I have an Action as follows that I am trying to track down the
Im thinking about building an application on our website to track order places through
Someone told me to do this in order to keep track of latest people
Order props: Object selectedItems: Array[1] 0: SelectedItem length: 1 __proto__: Array[0] __proto__: Order I
Order deny,allow deny from all allow from xx.xx.x.xx RewriteRule . - [F] I have
This only happens from time to time, seems random and I have not been
Not sure if this question makes for some poor performance down the track, but
In order no write a track in IGC format I need to transform the
I have a slow query in a Symfony2 project using Doctrine2. I am unsure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.