Issues with garbage collecting BreadcrumbItem and BreadcrumbButtton

Oct 9, 2008 at 2:02 PM
Edited Oct 9, 2008 at 2:05 PM
I tried to profile the test application and got the same behaviour as our application when we have used this library. We have some issues with garbage collecting the BreadcrumbItem and BreadcrumbButton objects because the lifetime of the objects that is the basis for the navigation, have a lifecycle which is longer than we wish for the lifetime of BreadcumbItems and buttons. I've had a hard time trying to cleanup the references because the dependencies isn't obvious in a WPF app.

Is it possible to implement a weaker connection between the objects that are the basis of the navigation three and the breadcrumb objects. This blog entry shows an example on how a WPF application can use a weak event pattern and maybe some ideas could be used for this library as well.

I've taken a screenshot from a profiler tool showing growing numbers of item and buttons in the demo application, but this discussionforum doesn't seem to allow attachements.

Any thoughts on how I can reduce the dependency to increase likehood of garbage collecting the item and buttons are greatly appreciated

Best regards,
Trond Andersen
Sep 6, 2010 at 2:40 PM

I found the same problem. I haven't profiled, but i have the feeling that the problem is that Breadcbrum buttons are registering to the IsPressedProperty value change, for which we also should unregister.

Also even if they are removed from the items collection, they still seem to keep a reference to the datacontext. 

What i ended up doing is make BreadcrumbItems and BreadcrumButtons to implement IDisposable, and then make sure that the button is not registerd to menu.opened or is pressed property.

From breadcbum RemoveItem method then i call the BreadcrumbItem.Dispose() which will call BreadcrumbButton.Dipose()