Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DisposeBag #2

Closed
seungchan2 opened this issue May 22, 2022 · 0 comments
Closed

DisposeBag #2

seungchan2 opened this issue May 22, 2022 · 0 comments
Assignees
Labels
Concept 기본 개념입니다.

Comments

@seungchan2
Copy link
Owner

seungchan2 commented May 22, 2022

Observable은 subscribe 이후 complete 또는 error 이벤트가 발생하기 전까지 계속 next 이벤트를 발생시킴

"계속" 이라는 단어를 다시 생각해보면 계속 동작한다는 의미임

만약 굳이 동작하지 않아도 되는 시점에 계속 동작이 된다면 메모리 누수로 이어짐

그래서 구독을 해제하는 방법이 필요함

그게 바로 DisposeBag

Rx에서 ARC를 관리하는 것이라고 생각하면 됨

만약 Observer가 너무 많은데 그 많은 Observer가 다 dispose를 실행하게 된다면, 비효율적임

그래서 DisposeBag을 통해 효율적으로 관리할 수 있음

스크린샷 2022-05-23 오후 7 55 43

클래스의 메모리가 해제되는 시점 (deinit이 되는 시점)에서 Disposable 되지만,

RootViewController일 경우에는 메모리에서 클래스가 해제되지 않음

따라서 끝까지 이벤트를 진행하고 Dispose 되거나, Dispose가 되지 않을 수 있음

이럴 경우 직접 관리를 해야 하며, 원하는 시점에 dispose 메서드를 호출해서 리소스를 정리

@seungchan2 seungchan2 added the Concept 기본 개념입니다. label May 22, 2022
@seungchan2 seungchan2 self-assigned this May 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Concept 기본 개념입니다.
Projects
None yet
Development

No branches or pull requests

1 participant