-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2258 from square/py/animator_leaks
Surface ObjectAnimator leaks
- Loading branch information
Showing
7 changed files
with
190 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
shark/src/main/java/shark/internal/InternalSharkCollectionsHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package shark.internal | ||
|
||
import shark.HeapObject | ||
import shark.HeapObject.HeapClass | ||
import shark.HeapObject.HeapInstance | ||
import shark.HeapObject.HeapObjectArray | ||
import shark.HeapObject.HeapPrimitiveArray | ||
|
||
/** | ||
* INTERNAL | ||
* | ||
* This class is public to be accessible from other LeakCanary modules but shouldn't be | ||
* called directly, the API may break at any point. | ||
*/ | ||
object InternalSharkCollectionsHelper { | ||
|
||
fun arrayListValues(heapInstance: HeapInstance): Sequence<String> { | ||
val graph = heapInstance.graph | ||
val arrayListReader = OpenJdkInstanceRefReaders.ARRAY_LIST.create(graph) | ||
?: ApacheHarmonyInstanceRefReaders.ARRAY_LIST.create(graph) | ||
?: return emptySequence() | ||
|
||
if (!arrayListReader.matches(heapInstance)) { | ||
return emptySequence() | ||
} | ||
|
||
return arrayListReader.read(heapInstance).map { reference -> | ||
val arrayListValue = graph.findObjectById(reference.valueObjectId) | ||
val details = reference.lazyDetailsResolver.resolve() | ||
"[${details.name}] = ${className(arrayListValue)}" | ||
} | ||
} | ||
|
||
private fun className(graphObject: HeapObject): String { | ||
return when (graphObject) { | ||
is HeapClass -> { | ||
graphObject.name | ||
} | ||
is HeapInstance -> { | ||
graphObject.instanceClassName | ||
} | ||
is HeapObjectArray -> { | ||
graphObject.arrayClassName | ||
} | ||
is HeapPrimitiveArray -> { | ||
graphObject.arrayClassName | ||
} | ||
} | ||
} | ||
} |