Skip to content

Commit eace0c7

Browse files
Fabio Carballofacebook-github-bot
authored andcommitted
Add ability to log non fatals regarding improper mount release
Summary: I'm adding a new non-fatal with the goal of identifying improper mount content releases into the Pool on IG. Hopefully this will be able to signal some situations that we are not being able to repro and then fix them, so as to avoid leaks. This will be only enabled for a small percentage of users, to avoid noise. Differential Revision: D60234842 fbshipit-source-id: 5d63809ede626b7cef49fccfb4f353b4178cee6f
1 parent 4ddb804 commit eace0c7

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

litho-rendercore/src/main/java/com/facebook/rendercore/MountItemPoolsReleaseValidator.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import java.lang.reflect.Field
3434
internal class MountItemPoolsReleaseValidator(
3535
private val failOnDetection: Boolean = false,
3636
private val excludedPatterns: Set<Regex> = emptySet(),
37+
private val onInvalidRelease: ((exception: InvalidReleaseToMountPoolException) -> Unit)? = null,
3738
/**
3839
* These are fields the client can add for custom fields they want to inspect. If you have a
3940
* custom view you can define a specific extraction that verifies if a listener was properly
@@ -119,6 +120,8 @@ internal class MountItemPoolsReleaseValidator(
119120
append("\n")
120121
}
121122

123+
onInvalidRelease?.invoke(InvalidReleaseToMountPoolException(result))
124+
122125
if (failOnDetection) {
123126
assert(false) { result }
124127
} else {
@@ -170,3 +173,9 @@ internal class MountItemPoolsReleaseValidator(
170173
}
171174

172175
private const val TAG = "MountReleaseValidator"
176+
177+
/**
178+
* This exception is thrown when a view is released to the pool but it has a listener or any other
179+
* view property that was not cleaned up.
180+
*/
181+
class InvalidReleaseToMountPoolException(message: String) : RuntimeException(message)

litho-rendercore/src/main/java/com/facebook/rendercore/MountItemsPool.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,10 +376,14 @@ object MountItemsPool {
376376
*/
377377
fun enableItemsReleaseValidation(
378378
failOnDetection: Boolean,
379-
excludedPatterns: Set<Regex> = emptySet()
379+
excludedPatterns: Set<Regex> = emptySet(),
380+
onInvalidRelease: (exception: InvalidReleaseToMountPoolException) -> Unit
380381
) {
381382
mountItemPoolsReleaseValidator =
382-
MountItemPoolsReleaseValidator(failOnDetection, excludedPatterns)
383+
MountItemPoolsReleaseValidator(
384+
failOnDetection = failOnDetection,
385+
excludedPatterns = excludedPatterns,
386+
onInvalidRelease = onInvalidRelease)
383387
}
384388

385389
/** Content item pools that RenderCore uses to recycle content (such as Views) */

0 commit comments

Comments
 (0)