Unable to release an internal reference to an object

Grids for WPF Forum

Posted 14 years ago by Craig - Varigence, Inc.
Version: 10.1.0521
We have an application that's somewhat similar to Visual Studio in that it has 'projects'. When we close a project, we're working to ensure that all the models and viewmodels tied to the project are released from memory. We're using the property grid in this app and we're hitting a situation where it fails to release an object reference. Subsequently, I'm hoping to find a way to free the object from within the PropertyGrid.

The repro:

1. We open a project and select an object (which in our case is a ViewModel but I don't think there's anything special about it being a ViewModel).
2. Our property grid has a multibinding that fires on selecting the object so the selected object's properties appear in the property grid.
3. I change one of the properties (say a true/false value).
4. I close the project and open our memory profiler - we're using ANTS. (In a simplified repro case, I believe you could simply set the multibinding's value to a 'new object()', thereby clearing the grid without breaking the binding).
5. In the ANTS profiler, I take a snapshot and I can see that:

The PropertyGrid's effectiveValues array has an entry whose value is a BindingExpression. The BindingExpression has a private '_binding' field, which in turn has a private '_source' field. The '_source' is an ExplicitObjectRef, whose '_object' field is a PropertyDescriptorDataAccessor. The DataAccessor has a 'd' field that is holding the reference to our ViewModel. Thus, there's a chain of references from the PropertyGrid, through its binding, to a DataAccessor that holds the object we want to free.

I've tried a bunch of ways to encourage the PropertyGrid to release the object, focusing on clearing the appropriate dependency properties (in my case, SelectedObject, SelectedObjects, IsEnabled, and DataContext, since these all have bindings). If I remove the bindings completely, then the problem seems to go away although it leaves the property grid useless when we load the next project and try selecting another object. If I use SetCurrentValue to clear the current values of the bindings, the bindings remain but this problem occurs.

When I looked at the EffectiveValue in the debugger, I could see its GlobalIndex is 1409. I couldn't map that to a particular DependencyProperty on the PropertyGrid so I suspect it may be an attached property, or VS may simply be reporting the wrong index.

So, to sum up my question, is there a way to break the lingering reference of the PropertyDescriptorDataAccessor so that I can free the object? Is the issue that there's some other dependency property that I need to clear?

As always, any help is greatly appreciated.



[Modified at 04/29/2010 04:31 PM]
The latest build of this product (v24.1.2) was released 2 months ago, which was after this thread was created.

Add Comment

Please log in to a validated account to post comments.