Alternative Way to Work with Memory
If you don't want to work with memory in a way described in Work with Memory, you have an alternative. We don't hide the "kernel" level of the framework which is based on the dotMemoryApi
static class. This class allows you to directly work with memory snapshots without using lambdas. Actually, the dotMemory.Check method is a wrapper of dotMemoryApi
calls.
You can use the dotMemoryApi
class to write your own wrapper or directly work with memory snapshots.
In the latter case, you should keep in mind the following peculiarities:
Taking a snapshot may be a time-consuming operation.
Snapshots contain memory data on the moment you take them, not on the moment you access them.
In case of errors in the test code, test runner will be unable to distinguish whether the test fails because of a dotMemory Unit call or other test code.
All dotMemory Unit calls should be preceded by the check on whether support for dotMemory Unit is enabled.
For example, the following assertion
can be rewritten as
dotMemoryApi static class
dotMemoryApi methods
Name | Description |
---|---|
| Returns a Snapshot instance which is a reference to memory data in the current execution point. Use this reference to get data about objects in memory, compare it with data from another snapshot, or get data about memory traffic between two snapshots. |
| Gets difference between Returns an instance of the SnapshotDifference type that contains data about objects that were allocated and collected in the time interval between getting the snapshots. |
| Gets data about memory traffic in the time interval between taking Returns an instance of the Traffic type that allows you to get data about objects that were allocated and collected during the specified time interval. |
| Saves the workspace containing all memory snapshots collected during unit test run using the directory path specified by |
dotMemoryApi properties
Name | Type | Description |
---|---|---|
|
| Returns |
|
| Defines whether the memory allocation data (memory traffic and creation stack trace data) must be collected. Set to |
Snapshot class
Represents memory data in some execution point.
Snapshot methods
Name | Description |
---|---|
| (Inherited from ObjectSet) Gets a subset of objects by a specific condition. The condition is defined by Returns an instance of the ObjectSet type. |
| (Inherited from ObjectSet) Returns a collection of objects of the TypeMemoryInfo type. Each object represents a particular type from the source object set and carries info about the number of objects of that type and their total size. |