Check for Objects
Check for objects of a specific type
Checking for objects of a specific type is the main way of finding memory leaks in your code.
A lambda is passed to the
Check
method of the static dotMemory type. What this method does is takes a dump of the managed heap. This method will be called only in case you run the test using Run test under dotMemory Unit.The
memory
object of the Memory type passed to the lambda contains all memory data for the current execution point.The GetObjects method returns a set of objects that match the condition passed in another lambda. E.g., what this line does is slices the memory by leaving only objects of the
Goo
type. The NUnitAssert
expression asserts that there should be 0 objects of theFoo
type.
Select objects by a number of conditions
To slice data by a number of conditions, you can build chains of GetObjects
calls. The ObjectSet type has two properties that you can use in test assertions:ObjectsCount
and SizeInBytes
.
dotMemory Unit also provides alternative syntax for object set queries. You can use the ==
, &
, and |
logic operators to combine a number of queries. For example:
Note that open generic types and interfaces are also supported. For example: