https://kotlinlang.org logo
#jvm-ir-backend-feedback
Title
# jvm-ir-backend-feedback
n

Nikhilkumar80

12/09/2021, 8:46 PM
I see this difference with the way garbage collection is handled after jvm-ir-backend change. In this code,
println(weakStateRef.get())
used to return
null
prior to upgrading. Now, it is not cleared when `System.gc()`is called. Is this expected?
Copy code
data class State(val stateKey: String? = null)

fun func1(newState: State) {
    // do nothing
}

fun func2() {
    val weakStateRef = WeakReference(State("Foo"))
    func1(weakStateRef.get()!!)
    System.gc()
    println(weakStateRef.get()) // State(stateKey="Foo")
}
u

udalov

12/10/2021, 7:43 PM
Thanks for the report. IR backend shouldn't need to store intermediate values into local variables (which makes them strongly retained until the stack frame is dropped) unless it's absolutely necessary, which in this case it isn't. Please report an issue at https://kotl.in/issue and we'll investigate if we can fix it.
n

Nikhilkumar80

12/11/2021, 5:49 AM
Thanks for the response. Here is the ticket: https://youtrack.jetbrains.com/issue/KT-50193
2 Views