Garbage collection when attached dependent object \ disabled

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

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

Here the value of "Top" is mapped to the DockPanels of the DockProperty through the text block "MyText" of the dependency object

But my question is when is this mapping located? The reason I'm asking is DockPanel DockProperty is static \ shared. Thus, it must have multiple Pair (Of value, dependency object) mappings that were associated with it in some internal dictionary. (just a hunch)

So it should be garbage collection when the dependency object is destroyed.

So, now my point is, is there any way I should know IF such depiction with attached property occurs (for example, some dispairing or dispose event for this attached property and dependency object)?

Also, if such garbage collection does not take place, is it not a memory leak?

Thanks Vinet Sanke.

+4
source share
2 answers

As I understand the new property system in WPF, DependecyObject itself saves this value. In your example, this will be a text block. Do not confuse when you call a static member - it should be implemented as:

 element.SetValue(DockPanel.TopProperty, value); 

Thus, static field storage is not saved.

+2
source

I think it was created using WeakReference. Therefore, the removal of empty links occurs periodically.

+1
source

All Articles