Debug.GetInstanceCount Method

Definition

Overloads

Name Description
GetInstanceCount(Class)

Counts the number of instances of the specified class.

GetInstanceCount(Class, Boolean)

Counts the number of instances of the specified class.

GetInstanceCount(Class)

Counts the number of instances of the specified class.

[Android.Runtime.Register("getInstanceCount", "(Ljava/lang/Class;)J", "", ApiSince=36)]
public static long GetInstanceCount(Java.Lang.Class cls);
[<Android.Runtime.Register("getInstanceCount", "(Ljava/lang/Class;)J", "", ApiSince=36)>]
static member GetInstanceCount : Java.Lang.Class -> int64

Parameters

cls
Class

Class the class to count instances of.

Returns

the number of matching instances.

Attributes

Remarks

Counts the number of instances of the specified class.

<b>Warning:</b> This operation can be expensive, as it may involve traversing portions of the Java heap. It is primarily intended for debugging purposes and should not be used in performance-critical code.

It's intended to help developers identify object leaks or to validate the number of instances of a specific class during development.

It is the caller's responsibility to do GC if they don't want unreachable objects to get counted.

Java documentation for android.os.Debug.getInstanceCount(java.lang.Class).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

GetInstanceCount(Class, Boolean)

Counts the number of instances of the specified class.

[Android.Runtime.Register("getInstanceCount", "(Ljava/lang/Class;Z)J", "", ApiSince=36)]
public static long GetInstanceCount(Java.Lang.Class cls, bool includeAssignable);
[<Android.Runtime.Register("getInstanceCount", "(Ljava/lang/Class;Z)J", "", ApiSince=36)>]
static member GetInstanceCount : Java.Lang.Class * bool -> int64

Parameters

cls
Class

Class the class to count instances of.

includeAssignable
Boolean

if true, any instance whose class is assignable to cls, as defined by Class#isAssignableFrom, is counted. If false, only instances whose class is equal to cls are counted.

Returns

the number of matching instances.

Attributes

Remarks

Counts the number of instances of the specified class.

<b>Warning:</b> This operation can be expensive, as it may involve traversing portions of the Java heap. It is primarily intended for debugging purposes and should not be used in performance-critical code.

It's intended to help developers identify object leaks or to validate the number of instances of a specific class during development.

It is the caller's responsibility to do GC if they don't want unreachable objects to get counted.

Java documentation for android.os.Debug.getInstanceCount(java.lang.Class, boolean).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to