The .NET Memory Profiler API can be used to control the profiler within the profiled process and to detect potential memory leaks using assertions. This API is very well suited for doing automated testing of memory usage errors, e.g., by using a unit testing framework such as NUnit or MSTest.
The API can be accessed by referencing the class library files MemProfiler.dll or MemProfiler2.dll. These files are installed under the Redist folder in the .NET Memory Profiler installation folder (default location: C:\Program files\SciTech\NetMemProfiler2\Redist). The MemProfiler.dll file can be used for both .NET Framework 1.x and 2.0, but MemProfiler2.dll can only be used for .NET Framework 2.0. It is recommended that the MemProfiler2.dll file be used for projects targeting .NET Framework 2.0 or later, since it handles generic types in the assertion methods.
This class library contains the two main classes of the API:
• SciTech.NetMemProfiler.MemProfiler
• SciTech.NetMemProfiler.MemAssertion
The MemProfiler class contains static methods that can be used to:
• Detect whether the current process is running under the profiler (MemProfiler.IsProfiling).
• Collect fast snapshots that can be used as a reference when doing memory assertions (MemProfiler.FastSnapshot).
• Collect full snapshots that will be saved by the profiler (MemProfiler.FullSnapshot).
• Add comments that will be shown in the real-time graph of the profiler (MemProfiler.AddComment).
The MemAssertion class contains static methods for asserting that certain class instances do not exist (NoInstances, NoNewInstances, and NoNewInstancesExcept). It also contains methods for grouping several assertions into one assertion session (BeginAssertions and EndAssertions).
For more information about the .NET Memory Profiler API methods, see the .NET Memory Profiler API Reference documentation.
More:
Using Assertions to Detect Memory Leaks
|
.NET Memory Profiler User Manual © Copyright 2002-2013. SciTech Software AB. For information about .NET Memory Profiler, see the product site at http://memprofiler.com .NET Memory Profiler is developed by SciTech Software AB |