79445161

Date: 2025-02-17 10:57:11
Score: 0.5
Natty:
Report link

Observable and disposable do not reference each other. Once observer is connected through a subscriber via a binding or using subscribe method on the observer, a subscription is created (events are triggered only when subscription happens).

All the subscriptions are generally stored in a disposeBag which is present as property inside a class (for example view controller) so that subscriptions are removed automatically when they are not needed (We can also store the references of subscriptions and manually call dispose method to remove it, however that is tedious). Once the class is removed from from memory, all its properties are also removed from memory, including the the dispose bag which contains all the subscriptions. Once the subscriptions are removed, observable will no longer emit event.

If the subscriptions are not removed, then the observable will keep on emitting the events and memory leak will happen.

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Low reputation (0.5):
Posted by: Pranav Pravakar