Browse Source

Convert to WeakReference in ExpressionObserver.

Doing a `Publish().Refcount()` caches the latest value so it can be sent
to subsequent subscribers, and this causes a leak. Convert the value
to/from `WeakReference` for that part.
pull/691/head
Steven Kirk 10 years ago
parent
commit
91b855b056
  1. 14
      src/Markup/Avalonia.Markup/Data/ExpressionObserver.cs

14
src/Markup/Avalonia.Markup/Data/ExpressionObserver.cs

@ -177,9 +177,11 @@ namespace Avalonia.Markup.Data
}
_result = Observable.Using(StartRoot, _ => source)
.Select(ToWeakReference)
.Publish(UninitializedValue)
.RefCount()
.Where(x => x != UninitializedValue);
.Where(x => x != UninitializedValue)
.Select(FromWeakReference);
}
return _result.Subscribe(observer);
@ -197,6 +199,16 @@ namespace Avalonia.Markup.Data
}
}
private static object ToWeakReference(object o)
{
return o is BindingNotification ? o : new WeakReference(o);
}
private static object FromWeakReference(object o)
{
return o is WeakReference ? ((WeakReference)o).Target : o;
}
private IDisposable StartRoot()
{
var observable = _root as IObservable<object>;

Loading…
Cancel
Save