Skip to content

Commit ef2efc5

Browse files
ellemac123meta-codesync[bot]
authored andcommitted
Fix testLoggerLeak by replacing Kotlin SAM lambda with anonymous object (#1977)
Summary: Pull Request resolved: #1977 Yoga test is failing after migration from java to kotlin due to the `testLoggerLeak` failing. The test creates a no-op `YogaLogger`, sets+unsets it on a config, drops all references, then asserts that a `WeakReference` to the logger gets cleared by GC. The Kotlin SAM lambda form (`YogaLogger { level, message -> }`) ends up with an implicit `this$0` capture of the enclosing test instance, so the logger never becomes weakly reachable and the test fails after 50 GC attempts. Fix: Replacing the SAM lambda with an explicit anonymous object expression to match what the Java version was doing. Reviewed By: cortinico Differential Revision: D108765169 fbshipit-source-id: 1f6ca4351f3f92bab27b522e5fb57b82fee0e995
1 parent b7ff95d commit ef2efc5

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

java/tests/com/facebook/yoga/YogaLoggerTest.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ class YogaLoggerTest {
5555
@Throws(Exception::class)
5656
fun testLoggerLeak() {
5757
val config = YogaConfigFactory.create()
58-
var logger: YogaLogger? = YogaLogger { level, message -> }
58+
@Suppress("ObjectLiteralToLambda")
59+
var logger: YogaLogger? =
60+
object : YogaLogger {
61+
override fun log(level: YogaLogLevel, message: String) {}
62+
}
5963
config.setLogger(logger)
6064
config.setLogger(null)
6165
val ref = WeakReference<Any>(logger)

0 commit comments

Comments
 (0)