My RxSwift Summary ④ (What is dispose bag?)

This article is My RxSwift Summary ①, My RxSwift Summary ②, My RxSwift Summary ③ (What is Observable?) is a continuation.

How to start is subscribe / How to end is dispose bag

ʻObservable has a feature that "it has 3 events ( next / error / completed), and by subscribing, it becomes possible to handle those elements ". There is a subscribe` to start, but how should I end it? There are three possible ways to start it.

--ʻErrorEvent is flowing --Thecompleted event is flowing --Add ʻobservarble to dispose bag

This time, I will describe the third dispose bag in detail.

What is a dispose bag?

Garbage bag for discarding ʻobservable`s at once

Why do you need it?

Some ʻobservables do not want to play completed or ʻerror (ex: 〇〇). In that case, it is necessary to explicitly complete (≒ discard) ʻobservable by using the dispose method provided in ʻobservable. (If you don't complete it, you'll be in a subscribe state forever, causing a memory leak.)

At that time, instead of using the dispose method individually for the ʻobservable, have adisposebag as a property of the instance that puts the ʻobservable together in order to reduce the management cost, and all at the timing of instance destruction. ʻObservable can be dispose(I often see patterns that have it as a property ofViewController`)

Recommended Posts

My RxSwift Summary ④ (What is dispose bag?)
My RxSwift Summary ③ (What is Observable?)
My RxSwift Summary ⑤ (What is Subjects / Relay?)
My RxSwift Summary ②
My RxSwift Summary ①
What is Java Assertion? Summary.
What is Cubby
What is Docker?
What is null? ]
What is java
What is Keycloak
What is maven?
What is Jackson?
What is Docker
What is self
What is Jenkins
What is ArgumentMatcher?
What is IM-Juggling?
What is params
What is SLF4J?
What is Facade? ??
What is Java <>?
What is Gradle?
What is POJO
What is Java
What is centOS
What is RubyGem?
What is programming?
What is before_action?
What is Docker
What is Byte?
What is Tomcat
What is Maven Assembly?
What is `docker-compose up`?
What is a constructor?
What is vue cli
What is an interface?
What is Ruby's self?
What is hard coding?
What is a stream
What is Ruby's attr_accessor?
What is Java Encapsulation?
What is permission denied?
What is instance control?
What is an initializer?
What is Spring Tools 4
What is an operator?
What is object orientation?
What is Guava's @VisibleForTesting?
What is MVC model?
What is an annotation?
What is Java technology?
What is Java API-java
What is @ (instance variable)?
What is Gradle's Artifact?
What is JPA Auditing?
[Swift] What is dismiss?
[Java] What is flatMap?
What is a Servlet?
What is web development?
[Java] What is JavaBeans?