Working with Object Sets
Object set is a number of objects selected by specific condition. To ease the understanding, think of an object
set as of the result of some query, like "Select all objects of the string type promoted to Gen 2",
or "Select all objects retained in memory by the instance A", and so on.
An ObjectSet
instance is returned as a result of the
ObjectSet.GetObjects
and ObjectSet.GetExclusivelyRetainedObjects
methods.
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
.
Example
For example, the following code asserts that there are no string
and
Foo
objects in the Large Object Heap:
dotMemory.Check(memory =>
{
Assert.That(memory.GetObjects(where => where.Type.Is(typeof(string), typeof(Foo)))
.GetObjects(where => where.Generation.Is(Generation.LOH)).ObjectsCount, Is.EqualTo(0));
});
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:
Assert.That(memory.GetObjects(where => where.Type == (typeof(string)) &
where.Generation == Generation.LOH).ObjectsCount, Is.EqualTo(0));
ObjectSet Class
Represents a set of objects in memory.
ObjectSet Methods
Name | Description |
---|---|
GetObjects(Func<ObjectProperty, Query> query): ObjectSet
|
Gets a subset of objects by a specific condition. The condition is defined by a
Query that should be returned by a lambda expression. The
ObjectProperty object
passed to the lambda allows creating queries that select objects by type, interface, and other parameters. Returns an instance of the ObjectSet type.
|
GetObjects(ObjectSetQuery objectSetQuery): ObjectSet
|
Gets a subset of objects by a specific condition. The condition is defined by a reusable query - an
instance of the ObjectSetQuery type. See
QueryBuilder
for
details. Returns an instance of the ObjectSet type.
|
GetExclusivelyRetainedObjects(): ObjectSet
|
Gets a set of objects that are
exclusively retained (dominated)
by the current object set. Returns an instance of the ObjectSet type.
|
ObjectSet Properties
Name | Type | Description |
---|---|---|
ObjectsCount
|
int
| Total number of objects in the set. |
SizeInBytes
|
long
| Total size of objects in the set in bytes. |
ObjectProperty Class
Selects objects in a set by a specific condition: type, interface, and others.
ObjectProperty Methods
Name | Description |
---|---|
LeakedOnEventHandler(): Query
|
Creates the "Select all objects that cause the event handlers leak" query.
Learn more. Returns Query that can be used by the GetObjects method.
|
IsNotDominated(): Query
|
Creates the query "Select all objects that are not
exclusively retained
in memory (in other words, objects that are retained by more than one object)". Returns Query that can be used by the GetObjects method.
|
ObjectProperty Properties
Name | Type | Description |
---|---|---|
Type
|
TypeProperty
| Allows selecting objects by type. |
Interface
|
InterfaceProperty
| Allows selecting objects by interface. |
Namespace
|
NamespaceProperty
| Allows selecting objects by namespace. |
Assembly
|
AssemblyProperty
| Allows selecting objects by assembly. |
Generation
|
GenerationProperty
| Allows selecting objects by generation. |
TypeProperty Class
TypeProperty
is used to create "select objects by type" queries.
TypeProperty Methods
Name | Description |
---|---|
Is(params Type[] typeList): Query
|
Creates the "Select all objects of particular types" query.
The list of types is passed in a
Type array. Open generic types are also supported.Returns Query that can be used by the GetObjects method.
|
Is<T>: Query
|
Creates the "Select all objects of a particular type" query. Open generic types are also supported. Returns Query that can be used by the GetObjects method.
|
IsNot(params Type[] typeList): Query
|
Creates the "Select all objects that do not belong to particular types" query.
The list of types is passed in a
Type array. Open generic types are also supported. Returns Query that can be used by the GetObjects method.
|
IsNot<T>: Query
|
Creates the "Select all objects that do not belong to a particular type" query.
Open generic types are also supported. Returns Query that can be used by the GetObjects method.
|
Like(params string[] typeWildcard): Query
|
Creates the "Select all objects of particular types" query.
The list of types is passed in a
string array. Asterisk (*) wildcards are allowed.Returns Query that can be used by the GetObjects method.
|
NotLike(params string[] typeWildcard): Query
|
Creates the "Select all objects that do not belong to particular types" query.
The list of types is passed in a
string array. Asterisk (*) wildcards are allowed.Returns Query that can be used by the GetObjects method.
|
InterfaceProperty Class
InterfaceProperty
is used to create "select objects by interface" queries.
InterfaceProperty Methods
Name | Description |
---|---|
Is(params Type[] typeList): Query
|
Creates the "Select all objects that implement particular interfaces" query.
The list of interfaces is passed in a
Type array. Open generic interfaces are also supported. Returns Query that can be used by the GetObjects method.
|
Is<T>: Query
|
Creates the "Select all objects that implement a particular interface" query.
Open generic interfaces are also supported. Returns Query that can be used by the GetObjects method.
|
IsNot(params Type[] typeList): Query
|
Creates the "Select all objects that do not implement particular interfaces" query.
The list of interfaces is passed in a
Type array. Open generic interfaces are also supported. Returns Query that can be used by the GetObjects method.
|
IsNot<T>: Query
|
Creates the "Select all objects that do not implement a particular interface" query.
Open generic interfaces are also supported. Returns Query that can be used by the GetObjects method.
|
Like(params string[] typeWildcard): Query
|
Creates the "Select all objects that implement particular interfaces" query.
The list of interfaces is passed in a
string array. Asterisk (*) wildcards are allowed.Returns Query that can be used by the GetObjects method.
|
NotLike(params string[] typeWildcard): Query
|
Creates the "Select all objects that implement particular interfaces" query.
The list of interfaces is passed in a
string array. Asterisk (*) wildcards are allowed.Returns Query that can be used by the GetObjects method.
|
NamespaceProperty Class
NamespaceProperty
is used to create "select objects by namespace" queries.
NamespaceProperty Methods
Name | Description |
---|---|
Like(params string[] namespaceWildcard): Query
|
Creates the "Select all objects that belong to particular namespaces" query.
The list of namespaces is passed in a
string array. Asterisk (*) wildcards are allowed.Returns Query that can be used by the GetObjects method.
|
NotLike(params string[] namespaceWildcard): Query
|
Creates the "Select all objects that do not belong to particular namespaces" query.
The list of namespaces is passed in a
string array. Asterisk (*) wildcards are allowed.Returns Query that can be used by the GetObjects method.
|
AssemblyProperty Class
AssemblyProperty
is used to create "select objects by assembly" queries.
AssemblyProperty Methods
Name | Description |
---|---|
Is(params Assembly[] assemblies): Query
|
Creates the "Select all objects that belong to particular assemblies" query.
The list of assemblies is passed in a
Assembly array. Returns Query that can be used by the GetObjects method.
|
IsNot(params Assembly[] assemblies): Query
|
Creates the "Select all objects that do not belong to particular assemblies" query.
The list of assemblies is passed in a
Assembly array. Returns Query that can be used by the GetObjects method.
|
Like(params string[] assemblyPattern): Query
|
Creates the "Select all objects that belong to particular assemblies" query.
The list of assemblies is passed in a
string array. Returns Query that can be used by the GetObjects method.
|
NotLike(params string[] assemblyPattern): Query
|
Creates the "Select all objects that do not belong to particular assemblies" query.
The list of assemblies is passed in a
string array. Returns Query that can be used by the GetObjects method.
|
GenerationProperty Class
GenerationProperty
is used to create "select objects by generation" queries.
GenerationProperty Methods
Name | Description |
---|---|
Is(params Generation[] generations): Query
|
Creates the "Select all objects from particular managed heap segments" query.
The list of heap segments is passed in a
Generation array. Returns Query that can be used by the GetObjects method.
|
IsNot(params Generation[] generations): Query
|
Creates the "Select all objects that do not belong to particular managed heap segments" query.
The list of heap segments is passed in a
Generation array. Returns Query that can be used by the GetObjects method. |
Generation Enum
Represents certain managed heap segments:
Value | Description |
---|---|
Gen1
| Generation 1 heap segment. |
Gen2
| Generation 2 heap segment. |
LOH
| Large object heap. |