=str #16986 Fix memory leak in PrefixAndTail when using Sink.publisher
The problem was reproduced with the TCK PrefixAndTailTest required_spec313_cancelMustMakeThePublisherEventuallyDropAllReferencesToTheSubscriber The tck subscriber was still referenced. Profiling revealed that the root cause was the VirtualPublisher that holds a reference to the realPublisher, which was MultiStreamOutputProcessor$SubstreamOutput, which had the reference to the subscriber. The VirtualPublisher is created by the Sink.publisher in the test, and the test holds on to that VirtualPublisher reference. The solution is to null out realPublisher field in the VirtualPublisher. The old workaround with the NullSubscriber was removed. Also made Sink.publisher reject additional subscribers.
This commit is contained in:
parent
050c0549f3
commit
2a975bfb35
7 changed files with 32 additions and 38 deletions
|
|
@ -311,7 +311,13 @@ private[stream] class VirtualSubscriber[T](val owner: VirtualPublisher[T]) exten
|
|||
*/
|
||||
private[stream] class VirtualPublisher[T]() extends Publisher[T] {
|
||||
@volatile var realPublisher: Publisher[T] = null
|
||||
override def subscribe(s: Subscriber[_ >: T]): Unit = realPublisher.subscribe(s)
|
||||
override def subscribe(s: Subscriber[_ >: T]): Unit = {
|
||||
val sub = realPublisher.subscribe(s)
|
||||
// unreference the realPublisher to facilitate GC and
|
||||
// Sink.publisher is supposed to reject additional subscribers anyway
|
||||
realPublisher = RejectAdditionalSubscibers[T]
|
||||
sub
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue