dotMemory Unit 2.3 Help

Comparing Snapshots

The SnapshotDifference type allows you to compare two memory checkpoints (snapshots) created by the dotMemory.Check method and get data about how many objects were created between snapshots and how many objects were collected. This may help you, for example, to determine ineffective memory usage or a memory leak. The object of the SnapshotDifference type is a result of the GetDifference method* of the Memory type.

Example

For example, the following code asserts that foo.Bar() creates 10 or less strings:

// Create first memory checkpoint var memoryCheckPoint1 = dotMemory.Check(); foo.Bar(); // some user code dotMemory.Check(memory => { // Compare two checkpoints Assert.That(memory.GetDifference(memoryCheckPoint1).GetNewObjects (where => where.Type.Is<string>()).ObjectsCount, Is.LessThan(10)); });

SnapshotDifference Class

Represents difference between two memory snapshots.

SnapshotDifference Methods

NameDescription
GetNewObjects(Func<ObjectProperty, Query> query): ObjectSet Gets a set of new objects - the ones that were created and not collected in the time interval between getting memory checkpoints.
Returns an instance of the ObjectSet type.
If query(optional) is specified, the resulting object set will be filtered by the condition defined in this query.
GetDeadObjects(Func<ObjectProperty, Query> query): ObjectSet Gets a set of "dead" objects - the ones that were created before getting the base memory checkpoint and collected in the time interval before getting the second checkpoint.
Returns an instance of the ObjectSet type.
If query(optional) is specified, the resulting object set will be filtered by the condition defined in this query.
GetSurvivedObjects(Origin from = Origin.NewSnapshot): ObjectSet Gets a set of survived objects - the ones that were created before getting the base memory checkpoint and not collected in the time interval before getting the second snapshot. The from parameter of the Origin type specifies the source of data about survived objects - newer or older memory checkpoint.
Returns an instance of the ObjectSet type.
If query(optional) is specified, the resulting object set will be filtered by the condition defined in this query.

Origin Enum

Represents memory checkpoints (snapshots) taken for comparison.

ValueDescription
OldSnapshot Older (base) memory checkpoint.
NewSnapshot Newer memory checkpoint.
Last modified: 23 May 2016