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

Retain cycle? #41

Open
Sajjon opened this issue Feb 25, 2018 · 2 comments
Open

Retain cycle? #41

Sajjon opened this issue Feb 25, 2018 · 2 comments

Comments

@Sajjon
Copy link

Sajjon commented Feb 25, 2018

Hey! Awesome project! Your code is so inspiring!

I just have one short question, in your ViewModels transform:input method you do use capture list to weakify self, e.g. in EditPostViewModel

        let savePost = saveTrigger.withLatestFrom(post)
                .flatMapLatest { post in
                    return self.useCase.save(post: post)
                            .trackError(errorTracker)
                            .asDriverOnErrorJustComplete()
                }

You use self.useCase.save, isn't this a retain cycle? Dont we have to use:

        let savePost = saveTrigger.withLatestFrom(post)
                .flatMapLatest { [weak self] post in
                    guard let `self` = self else { return someStuff }
                    return self.useCase.save(post: post)
                            .trackError(errorTracker)
                            .asDriverOnErrorJustComplete()
                }

Thanks!

@Sajjon
Copy link
Author

Sajjon commented Feb 28, 2018

I saw that you actually use capture list in CreatePostViewModel:

.flatMapLatest { [unowned self] in
                    return self.createPostUseCase.save(post: $0)
                            .trackActivity(activityIndicator)
                            .asDriverOnErrorJustComplete()
                }

But you use unowned self which would result in a crash if it were to be deallocated right?

@sergdort
Copy link
Owner

sergdort commented Mar 4, 2018

Hi, @Sajjon

Regarding:

I just have one short question, in your ViewModels transform:input method you do use capture list to weakify self, e.g. in EditPostViewModel

I do not think it's a retain cycle as we do not keep reference to the savePost observable. It's retained by the disposeBag in the ViewController which will release everything on deinit.
So there is no need even for unowned in the CreatePostViewModel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants