Skip to content
🤔 Documentation issue? Report it

//leakcanary/shark/HeapObject/HeapInstance

HeapInstance

class HeapInstance : HeapObject

An instance in the heap dump.

Functions

Name Summary
get operator fun get(declaringClassName: String, fieldName: String): HeapField?
operator fun get(declaringClass: KClass<out Any>, fieldName: String): HeapField?
instanceOf infix fun instanceOf(className: String): Boolean
Returns true if this is an instance of the class named className or an instance of a subclass of that class.
infix fun instanceOf(expectedClass: KClass<*>): Boolean
infix fun instanceOf(expectedClass: HeapObject.HeapClass): Boolean
Returns true if this is an instance of expectedClass or an instance of a subclass of that class.
readAsJavaString fun readAsJavaString(): String?
If this HeapInstance is an instance of the String class, returns a String instance with content that matches the string in the heap dump. Otherwise returns null.
readField fun readField(declaringClassName: String, fieldName: String): HeapField?
Returns a HeapField object that reflects the specified declared field of the instance represented by this HeapInstance object, or null if this field does not exist. The declaringClassName specifies the class in which the desired field is declared, and the fieldName parameter specifies the simple name of the desired field.
fun readField(declaringClass: KClass<out Any>, fieldName: String): HeapField?
readFields fun readFields(): Sequence<HeapField>
The fields of this instance, as a sequence of HeapField.
readRecord open override fun readRecord(): HprofRecord.HeapDumpRecord.ObjectRecord.InstanceDumpRecord
Reads and returns the underlying InstanceDumpRecord.
toString open override fun toString(): String

Properties

Name Summary
asClass val asClass: HeapObject.HeapClass?
This HeapObject as a HeapClass if it is one, or null otherwise
asInstance val asInstance: HeapObject.HeapInstance?
This HeapObject as a HeapInstance if it is one, or null otherwise
asObjectArray val asObjectArray: HeapObject.HeapObjectArray?
This HeapObject as a HeapObjectArray if it is one, or null otherwise
asPrimitiveArray val asPrimitiveArray: HeapObject.HeapPrimitiveArray?
This HeapObject as a HeapPrimitiveArray if it is one, or null otherwise
byteSize val byteSize: Int
graph open override val graph: HeapGraph
The graph of objects in the heap, which you can use to navigate the heap.
instanceClass val instanceClass: HeapObject.HeapClass
The class of this instance.
instanceClassId val instanceClassId: Long
The heap identifier of the class of this instance.
instanceClassName val instanceClassName: String
The name of the class of this instance, identical to Class.getName.
instanceClassSimpleName val instanceClassSimpleName: String
Returns instanceClassName stripped of any string content before the last period (included).
isPrimitiveWrapper val isPrimitiveWrapper: Boolean
Whether this is an instance of a primitive wrapper type.
objectId open override val objectId: Long
The heap identifier of this object.
objectIndex open override val objectIndex: Int
An positive object index that’s specific to how Shark stores objects in memory. The index starts at 0 and ends at HeapGraph.objectCount - 1. There are no gaps, every index value corresponds to an object. Classes are first, then instances, then object arrays then primitive arrays.
positiveObjectId val positiveObjectId: Long
objectId masked to be a positive unique identifier, as reported in Android Studio.
recordSize open override val recordSize: Int
The total byte size for the record of this object in the heap dump.

Extensions

Name Summary
hexIdentityHashCode val HeapObject.HeapInstance.hexIdentityHashCode: String?
The system identity hashCode represented as hex, or null if it couldn’t be found. This is the string identifier you see when calling Object.toString() at runtime on a class that does not override its hashCode() method, e.g. com.example.MyThing@6bd57cf
identityHashCode val HeapObject.HeapInstance.identityHashCode: Int?
The system identity hash code, or null if it couldn’t be found.