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
The caching used for
Sinks.many().replay().latest()holds bothheadandtailin 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
Possible Solution
Your Environment
doesn't bloody matter