Skip to content

Optimizer removes assignment too eagerly => memory leaks? #5313

@scabug

Description

@scabug

The null assignment in the following snippet is removed when compiled with -optimise which leads to different behavior and can result in memory leaks. It seems to be a bit of an edge case, since obj is a local var, but it is surprising nonetheless. I actually encountered this in a unit test testing for leaks, where a setup like below can be common.

object WeakBug {
  def main(args: Array[String]) {
    var obj = new Object {}
    val ref = new java.lang.ref.WeakReference(obj)
    obj = null
    System.gc()
    //Thread.sleep(500)
    assert(ref.get == null)
    println(ref.get)
  }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions