This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi, I'm using WpfElements 4.0 (dll version 5.1.1706.21879). In one of my views, I present hundreds of browsable items and each of them, when selected, displays a very complex property grid (pretty much unique for each of them). Each property grid increase the memory by several MB. It seems that the template cache is keeping a reference on each of them indefinitely. Moreover, when I select back an already displayed item, the memory continue to increase (I would have thought the cache would take care of it). I'm looking for a way to disable the cache, and/or to limit the number of template kept in it, and/or to dispose them after a certain time, and/or make it work. Any idea? Thanks, Laurent G. |
|
|
Well, I'm probably wrong, there is no cache inside the control... I'm still looking for what is keeping my objects alive. |
|
|
Hello Laurent I have not been able to find any memory leaks in the PropertyGrid. If you have a simple project that reproduces the problem and you need help with tracking it down, feel free to send it over and I'll have a look into it. Jason Fauchelle |
|
|
Hi Jason, Thanks for your reply. It seems not directly related to the control itself but more the way I'm using it. See in the picture attached, an event handler is the root of the reference chain that keeps my object alive (by the intermediary of a MindScape object). It looks like related to the ICollectionView I'm creating from my original observable collection. I'm setting to this collection view two SortDescriptions, a Filter and a GroupDescription. This collection is bound to a ItemsControl which embed through an ItemTemplate a PropertyGrid for each item.
Then the initializer method:
pg.InitializeEditors is an extension declared as follow:
When the view object is detached from the tree view, only the reference you can see in the attached file is still alive. I tried to remove from the collection view the different objects I attached to it but without any success. I definitely think that I'm missing some uninitialization. The code base is pretty much large, and I'm not sure to be able to do a simpler version easily. I'll let you know if I find anything interesting. |
|
|
Hello Laurent Thanks for the code snippets and the profiler image. I've looked into this further this week. I was unable to exactly reproduce the profiler results you got, but I did find a memory leak which may be related. I have resolved this memory leak which you can get in the next nightly build. The next nightly build will be available at around 1200 GMT. Nightly builds can be downloaded from here: http://www.mindscapehq.com/products/wpfelements/nightly-builds When you've installed the next nightly build, try it out in the profiler again. If the model objects still seem to be hanging around, take an extra Memory Snapshot, sometimes the GC is not fully finished in the profiler results after taking a snapshot. If the model objects are definitely still hanging around, there is a trick you could try: For all the non-DependancyObject model classes, make them implement INotifyPropertyChanged even if they don't need to. If they do not implement INotifyPropertyChanged, the WPF framework tends to hold onto them forever if they participate in data binding. If all else fails, you can set PropertyGrid.NodeClearanceMode to Aggressive which will completely remove all references the PropertyGrid has to your model objects. In order for this to work, make sure to set SelectedObject to null when you're done with a particular PropertyGrid instance. Jason Fauchelle |
|
|
Hi Jason, Thanks for your answer. I found the issue but forgot to mention it. Here was my trouble. When setting:
it seems that the ListCollectionView of PropertyGridRow is registering an EventHandler to PropertyChanged of the class PropertyGrouping. As this property is static, it cannot be garbage collected. The EventHandler is strong referenced by the Event, preventing the whole chain to be garbage collected. I solved the problem by adding an EventHandler to PropertyGrid object in xaml:
Then
By doing so, the EventHandler to PropertyChanged is removed and no more strong reference keeps the PropertyGrid alive. I think you have three options: removing this event handler when unloading the PropertyGrid object or overriding the PropertyChanged event by a weak pattern implementation or not declaring the class and property static. What do you think? Was your fix related? Regards, Laurent |
|
|
Erratum:
You should have read instead:
|
|
|
Hello Laurent Thanks for this information. My previous fix was not related to this issue. I have resolved this memory leak by implementing your fix within the PropertyGrid control. This fix will be available in the next nightly. When you install the next nightly build, you will not need to listen to the Unloaded event or set the Grouping to null. Jason Fauchelle |
|
|
Nice to see a so responsive service on your side, thanks. Laurent |
|