-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed as not planned
Labels
status/declinedWe feel we shouldn't currently apply this change/suggestionWe feel we shouldn't currently apply this change/suggestion
Description
The caching used for Sinks.many().replay().latest()
holds both head
and tail
in the cache, although only one is available for replay (as it should). This means that the extra reference holds unnecessary memory, and holds onto a reference that cannot be reclaimed.
Expected Behavior
The cache holds only a single reference in memory.
Actual Behavior
The https://github.com/reactor/reactor-core/blob/main/reactor-core/src/main/java/reactor/core/publisher/FluxReplay.java#L774 SizeBoundReplayBuffer holds two items in cache.
Steps to Reproduce
package reactor.core.publisher;
@Test
void reproCase() {
var replayBuffer = new FluxReplay.SizeBoundReplayBuffer<Integer>(1);
replayBuffer.add(11);
replayBuffer.add(22);
assert replayBuffer.head != replayBuffer.tail;
assert replayBuffer.head.value != replayBuffer.tail.value;
}
Possible Solution
package reactor.core.publisher;
@Test
void fixCase() {
var replayBuffer = new FluxReplay.SizeBoundReplayBuffer<Integer>(0);
replayBuffer.add(11);
replayBuffer.add(22);
assert replayBuffer.head == replayBuffer.tail;
assert replayBuffer.head.value == replayBuffer.tail.value;
assert replayBuffer.head.value == 22;
}
Your Environment
doesn't bloody matter
- Reactor version(s) used: 3.5.0
Metadata
Metadata
Assignees
Labels
status/declinedWe feel we shouldn't currently apply this change/suggestionWe feel we shouldn't currently apply this change/suggestion