Skip to content

Commit

Permalink
Merge pull request #10019 from hepin1989/vectorClean
Browse files Browse the repository at this point in the history
[backport] Avoid retaining refs to previously added items after VectorBuilder.clear
  • Loading branch information
lrytz committed May 2, 2022
2 parents b83e3c0 + 9ea6291 commit 7dbc139
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/library/scala/collection/immutable/Vector.scala
Expand Up @@ -678,6 +678,11 @@ final class VectorBuilder[A]() extends ReusableBuilder[A, Vector[A]] with Vector
}

def clear(): Unit = {
display5 = null
display4 = null
display3 = null
display2 = null
display1 = null
display0 = new Array[AnyRef](32)
depth = 1
blockIndex = 0
Expand Down
8 changes: 8 additions & 0 deletions test/junit/scala/collection/immutable/VectorTest.scala
Expand Up @@ -5,6 +5,8 @@ import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.junit.Test

import scala.tools.testing.AssertUtil._

@RunWith(classOf[JUnit4])
class VectorTest {

Expand All @@ -27,4 +29,10 @@ class VectorTest {
assertEquals(v, v drop Int.MinValue)
assertEquals(v, v dropRight Int.MinValue)
}
@Test def `VectorBuilder.clear retains nothing`: Unit = {
val b = new VectorBuilder[Object]()
val x = new Object
for (_ <- 0 to 16384) b += x
assertNotReachable(x, b)(b.clear())
}
}
2 changes: 2 additions & 0 deletions test/junit/scala/lang/primitives/BoxUnboxTest.scala
Expand Up @@ -5,13 +5,15 @@ import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4

import scala.annotation.nowarn
import scala.tools.testing.RunTesting

object BoxUnboxTest {
class VCI(val x: Int) extends AnyVal { override def toString = "" + x }
}

@RunWith(classOf[JUnit4])
@nowarn("msg=comparing values")
class BoxUnboxTest extends RunTesting {

@Test
Expand Down
4 changes: 3 additions & 1 deletion test/junit/scala/reflect/internal/NamesTest.scala
@@ -1,11 +1,12 @@
package scala.reflect.internal

import scala.tools.testing.AssertUtil._
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.junit.Test
import org.junit.Assert._
import scala.annotation.nowarn
import scala.tools.nsc.symtab.SymbolTableForUnitTesting
import scala.tools.testing.AssertUtil._

@RunWith(classOf[JUnit4])
class NamesTest {
Expand Down Expand Up @@ -33,6 +34,7 @@ class NamesTest {
assertTrue(h1 != f)
}

@nowarn("msg=comparing values")
@Test
def termNamesNotEqualsTypeNames() {
assert(h1 ne h1y)
Expand Down
Expand Up @@ -13,7 +13,6 @@ import scala.reflect.internal.util.JavaClearable
import scala.tools.asm.tree._
import scala.tools.nsc.backend.jvm.BackendReporting._
import scala.tools.nsc.reporters.StoreReporter
import scala.tools.testing.AssertUtil._
import scala.tools.testing.BytecodeTesting
import scala.tools.testing.BytecodeTesting._

Expand Down
Expand Up @@ -11,7 +11,6 @@ import scala.collection.JavaConverters._
import scala.tools.asm.Opcodes._
import scala.tools.asm.tree.ClassNode
import scala.tools.nsc.backend.jvm.AsmUtils._
import scala.tools.nsc.reporters.StoreReporter
import scala.tools.partest.ASMConverters._
import scala.tools.testing.BytecodeTesting
import scala.tools.testing.BytecodeTesting._
Expand Down
2 changes: 1 addition & 1 deletion test/junit/scala/tools/testing/TempDir.scala
Expand Up @@ -2,7 +2,7 @@ package scala.tools.testing

import java.io.{IOException, File}
import java.nio.file.{Path, Files}
import scala.util.{Properties, Try}
import scala.util.Properties
import Using.Releasable

object TempDir {
Expand Down

0 comments on commit 7dbc139

Please sign in to comment.