views:

108

answers:

2

Hi Guys,

When we use any attached property against any dependency object, I thunk it actually maps the property and the value with the dependency object.

E.g. <DockPanel><TextBlock x:Name="MyText" DockPanel.Dock="Top"/></DockPanel>

Here value "Top" is mapped with DockPanels DockProperty via the dependency object textblock "MyText"

But my question is when is this mapping disposed? The reason I am asking this is the DockPanel's DockProperty is static\shared. So it must be having such multiple mappings Pair (Of value, dependency object) maitained against it in some kind of internal dictionary. (just a guess)

So this must be garbage collected when the dependency object is destroyed.

So now my point is is there any way that I should know IF such attached property diposing is taking place (like some kind of dispairing or dispose event for the given attached property and dependency object)?

Also if such garbage collection doesnt take place then isnt this a memory leak?

Thx Vinit Sankhe.

A: 

I think it was created using WeakReference. So removing of empty references takes place periodically.

Trickster
A: 

As I understand the new property system in the WPF, the DependecyObject itself stores the value. In your example, this would be the textblock. Don't get confused as you call a static member - it is supposed to be implemented like:

element.SetValue(DockPanel.TopProperty, value);

So there happens no static field storage.

winSharp93