-
Notifications
You must be signed in to change notification settings - Fork 23
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 #44
Comments
The problem is the same in EventPipeline.swift
|
Thank you @ZoltanKapi for supporting Amplitude! I think I am curious are you using any tool to detect this, would love to learn more. Thank you! |
Thank you @liuyang1520 for the quick response! Here is a dummy example:
If you put this code snippet into a playground, you can't see any print in the console, because object C has a strong reference for object A, which will prevent the deallocation. I think exactly for this reason it is not a good idea this design where the object graph is not clear tree without any loop. Apple's original solution for this problem is the delegate pattern. (you can use swiftlint to force that all delegate object should be stored in a weak property) Also with delegate protocols you can easily slice the code into smaller, more maintainable pieces. |
Thank you @ZoltanKapi for the detailed explanations! As mentioned, I think For
Thanks! |
You still can have the init with non-optional parameter, but inside it would be weak. The strong link to the Amplitude class must be hold in once place (user-space code). |
This should be fixed in 1.5.0 |
Probably, most of the users will not notice it, because the instance will be stored in a static var or something similar and will live while the app.
But this strong reference causes retain cycle.
Amplitude-Swift/Sources/Amplitude/Timeline.swift
Line 11 in 0aea976
The text was updated successfully, but these errors were encountered: