Question about leaking dependencies #61
Unanswered
WedgeSparda
asked this question in
Q&A
Replies: 1 comment 4 replies
-
Hi @WedgeSparda, are you sure you pushed the final commit to your sample repo? It seems to be a blank project right now. Also I'm not familiar with the term "Composition Root". Do you have some references for that? |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, at our dev team we're exploring the possibility to use the dependencies library in order to replace our DI system.
Right now we're using big types (Composition Roots) creating all repositories and use cases and generating the presenters and views (we're using SwiftUI and UIKit since is a project with a long history).
Using those Composition Roots we create a model tree where we lazy implement what we need just in time. But there is an scenario where part of that tree needs to be recreated completely.
Since @dependency lives staticly, once is created there is no need to create it again and that works for almost all possible scenarios. But let's say one of those dependencies is a use case with a timer, geolocation listener or another recurrent work. Once the dependency is created, that work will continue forever.
I've created this silly project example to show what I mean. Project is presenting a modal which uses two use cases as dependencies.
After swipping down the modal to dismiss it, SubscribeToTimer is removed from memory (but I see is still part of DependencyValues) but StartTimer is not. I'm guessing the reason behind this problem is the timer but wanted to ask in order to confirm my suspicious.
If this is the case, I'm guessing the only possible solution would be to add extra logic to the use case to check if there is stop and dealocate the timer in case there is no longer subscriptions listening, right?
Sorry if this questions sound a bit silly? Still getting my head around this amazing library.
Thanks for your time and amazing job with Dependencies.
Beta Was this translation helpful? Give feedback.
All reactions