-
-
Notifications
You must be signed in to change notification settings - Fork 112
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
What about WeakReference<Observer<T>>
instead of Observer<T>
?
#307
Comments
I don't want to take the WeakReference approach.
Of course, solving memory leak issues in Rx programming is important. |
It should downgrade performance. At least because that is an extra wrapper. Also if there is any list of Observers, it should to shrink time to time when some objects are finalized. I can do the research and test in a case if I would know the idea at least has a chance to be integrated if everything would work:
Just please let me know @neuecc if this theoretically acceptable change.
When everything what points to the instance is also uses WeakReference - it is fine. I am testing the same thing in my Unity-ImageLoader package, works beautifully to release Texture from memory when there is no references left, without explicit |
In the past, there was active discussion about approaches using WeakReference in WPF, but I didn't view it very positively. |
Classical issue - memory leak because someone forgot to unsubscribe ⚠
Looks like we can resolve the dirty problem in a pretty beautiful way. Instead of forcing a developer to Dispose subscription explicitly, we can use
WeakReference
under the hood. Which will bring a minor opposite problem. As a result if developer won't store theIDisposable
(subscriber
) reference, the subscription would "expire".I believe this "opposite" problem is better because:
On other hand, if to keep doing as we are doing right now with hard reference, the memory leak problem that we have is extremely unintuitive and badly discoverable. Also it happens much later after the initial subscription which doesn't help.
Current source
R3/src/R3/Subject.cs
Line 294 in 9b18209
Update proposition
Of course it would require some amount of refactoring, the Observer has around 10 use spots, not too bad.
Please let me know if I am going to crazy, but it seems as "simplification" of existed things in the world of reactive programming to me. I am curious what do you think about this idea?
The text was updated successfully, but these errors were encountered: