I'm fresh at Rx, I have seem Observable buffer event data. With cold observable
or replay
that makes data stream will emit to later observer even through long time later. But when it will be garbaged?Besides, what's should be care for memory when use Rx?
Asked
Active
Viewed 277 times
0

LoranceChen
- 2,453
- 2
- 22
- 48
1 Answers
1
The garbage collection follows the normal rules for Java: If there's a hard reference to it it will persist forever. This means that if you have an Observable assigned to a field, that observable will not be eligible for garbage collection. If that is the result of a replay() operator - or if a replay() operator is upstream of it - then all the data in the replay() operator is also kept in memory.
There are replay
variants that can help you limit the referenced objects that are kept in memory either with a timeout or by count.
You can also use a SoftReference
to the observable itself.

Tassos Bassoukos
- 16,017
- 2
- 36
- 40
-
With a further search,I'm also nearly find reference description of this topic.Straightly saying, how much Rx style will use additional memory compare with normal workflow? Can quantization of the usage of a Observable able to count,contains some operation,such as map?em...thanks for any advice. – LoranceChen Mar 29 '16 at 12:40