I see this difference with the way garbage collect...
# jvm-ir-backend-feedback
n
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
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
Thanks for the response. Here is the ticket: https://youtrack.jetbrains.com/issue/KT-50193