Uploaded image for project: 'Scala Programming Language'
  1. Scala Programming Language
  2. SI-5313

Optimizer removes assignment too eagerly => memory leaks?

    Details

      Description

      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)
        }
      }
      

        Attachments

          Activity

            People

            • Assignee:
              jamesiry James Iry
              Reporter:
              imaier Ingo Maier
            • Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: