CalculatedProperties
CalculatedProperties copied to clipboard
Feature/fix memory leak
There's a memory leak if source property sits on a long living object while target is on a short living object. Simple fix is to wrap target properties in WeakReference
used ConditionalWeakTable to improve add/remove performance. List of weak references still needed to iterate alive targets
Performance test case:
- Initial wiring: Create source with 50,000 immediate targets
- Re-wiring: unplug an old target and add a new target, repeat 50,000 times
Results on my machine (Release)
- with HashSet: 0.2 sec for initial wiring and 0.3-0.4 sec for re-wiring
- with ConditionalWeakTable: 0.3-0.4 sec for initial wiring and 0.7-0.8 sec for re-wiring