views:

621

answers:

1

This is a C# (v3.0) Winforms problem.

I have a big object that is associated with a BindingSource. When I have done with this object and the BindingSource, I want to remove the reference from the BindingSource so the object can be released. I used BindingSource.Clear(). But after that, in the memory profiler, I can still see the object alive and the only reference is from the BindingSource.lastCurrentItem.

My question is, how should I remove the reference from the BindingSource? Thanks.

A: 

What happens when you set BindingSource.DataSource = null?

BindingSource.Clear() clears all elements in the underlying list (BindingSource.List), but doesn't remove the reference to the data source. (Reference)

lc
I have tried setting BindingSource.DataSource = null but the reference still exists, which is wired to me.
Steve
By the way, the BindingSource has a chain. So rootBS.DataSource = bigObject; And later, childBS.DataSource = rootBS; childBS.DataMember = "xxx"; I don't know if this is the case, is there any particular order that I have to follow to remove references of bigObject from both rootBS and childBS. Thanks.
Steve