Skip to content
🤔 Documentation issue? Report it

//leakcanary/shark/HeapObject/HeapClass/name

name

val name: String

The name of this class, identical to Class.getName. If this class is an array class, the name has a suffix of brackets for each dimension of the array, e.g. com.Foo[][] is a class for 2 dimensional arrays of com.Foo.

The behavior for primitive types changes depending on the VM that dumped the heap. JVM heap dumps don’t have any HeapClass object for primitive types, instead the java.land.Class class has 9 instances (the 8 primitive types and void). Android heap dumps have an HeapClass object for primitive type and the java.land.Class class has no instance.

If this is an array class, you can find the component type by removing the brackets at the end, e.g. name.substringBefore(‘[‘). Be careful when doing this for JVM heap dumps though, as if the component type is a primitive type there will not be a HeapClass object for it. This is especially tricky with N dimension primitive type arrays, which are instances of HeapObjectArray (vs single dimension primitive type arrays which are instances of HeapPrimitiveArray).