summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2013-01-27 09:42:48 -0800
committerJason Zaugg <jzaugg@gmail.com>2013-01-27 09:42:48 -0800
commitda6fc7aad705d96491e57dab1771be0cb7623206 (patch)
tree5a19cde82b6d3f733216be5c38ea2da3abcf2680
parent39ac8991944ebf1a7482a3e806c3c3c31ed8161c (diff)
parent62111a4f15dcca34476a543facc9613bdd79008a (diff)
downloadscala-da6fc7aad705d96491e57dab1771be0cb7623206.tar.gz
scala-da6fc7aad705d96491e57dab1771be0cb7623206.tar.bz2
scala-da6fc7aad705d96491e57dab1771be0cb7623206.zip
Merge pull request #1977 from retronym/ticket/7018
SI-7018 Fix memory leak in Attachments
-rw-r--r--src/reflect/scala/reflect/macros/Attachments.scala14
-rw-r--r--test/files/run/t6028.check2
2 files changed, 9 insertions, 7 deletions
diff --git a/src/reflect/scala/reflect/macros/Attachments.scala b/src/reflect/scala/reflect/macros/Attachments.scala
index a77cebf415..eeb87fafcc 100644
--- a/src/reflect/scala/reflect/macros/Attachments.scala
+++ b/src/reflect/scala/reflect/macros/Attachments.scala
@@ -44,17 +44,19 @@ abstract class Attachments { self =>
* Replaces an existing payload of the same type, if exists.
*/
def update[T: ClassTag](attachment: T): Attachments { type Pos = self.Pos } =
- new NonemptyAttachments(this.pos, remove[T].all + attachment)
+ new NonemptyAttachments[Pos](this.pos, remove[T].all + attachment)
/** Creates a copy of this attachment with the payload of the given class type `T` removed. */
def remove[T: ClassTag]: Attachments { type Pos = self.Pos } = {
val newAll = all filterNot matchesTag[T]
if (newAll.isEmpty) pos.asInstanceOf[Attachments { type Pos = self.Pos }]
- else new NonemptyAttachments(this.pos, newAll)
+ else new NonemptyAttachments[Pos](this.pos, newAll)
}
+}
- private class NonemptyAttachments(override val pos: Pos, override val all: Set[Any]) extends Attachments {
- type Pos = self.Pos
- def withPos(newPos: Pos) = new NonemptyAttachments(newPos, all)
- }
+// SI-7018: This used to be an inner class of `Attachments`, but that led to a memory leak in the
+// IDE via $outer pointers.
+private final class NonemptyAttachments[P >: Null](override val pos: P, override val all: Set[Any]) extends Attachments {
+ type Pos = P
+ def withPos(newPos: Pos) = new NonemptyAttachments(newPos, all)
}
diff --git a/test/files/run/t6028.check b/test/files/run/t6028.check
index 34f4b22134..79deaacf3a 100644
--- a/test/files/run/t6028.check
+++ b/test/files/run/t6028.check
@@ -15,7 +15,7 @@ package <empty> {
}
};
def bar(barParam: Int): Object = {
- @volatile var MethodLocalObject$module: runtime.VolatileObjectRef = new runtime.VolatileObjectRef(<empty>);
+ @volatile var MethodLocalObject$module: runtime.VolatileObjectRef = new runtime.VolatileObjectRef(null);
T.this.MethodLocalObject$1(barParam, MethodLocalObject$module)
};
def tryy(tryyParam: Int): Function0 = {