Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6556169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:54:37+00:00 2026-05-25T12:54:37+00:00

well,i tried this and the memory profiler shows that the problem still not solved,

  • 0

well,i tried this and the memory profiler shows that the problem still not solved,
actually i removed the I was creating a DependencyProperty Changed with a callback method using the following code:

public void RegisterForNotification(string propertyName, FrameworkElement element, PropertyChangedCallback callback) 
{ 
    Binding b = new Binding(propertyName) { Source = element }; 
    var prop = System.Windows.DependencyProperty.RegisterAttached( 
        "ListenAttached" + propertyName, 
        typeof(object), 
        typeof(UserControl), 
        new System.Windows.PropertyMetadata(callback));              
    element.SetBinding(prop, b); 
}  

well,i tried this and the memory profiler shows that the problem still not solved,
actually i removed the element.SetBinding(prop, b); and the memory leak still happen so i thisnk the cause of it is not the binding it self but this code:
var prop = System.Windows.DependencyProperty.RegisterAttached(
“ListenAttached” + propertyName,
typeof(object),
typeof(UserControl),
new System.Windows.PropertyMetadata(callback));

when i use null instead of callback the leak didnt happen. that means that the cause is the callback method not binding,is there any way to unregister it? or register it in another way so it doesnt cause the leak?

Thanks alot Phil Sandler it realy helps and work fine

i was trying to add visibilitychanged listener to my user control so i call the method as
RegisterForNotification(“Visibility”, this,callback),that was causing the memory leak,

i used what you sugested like this:

public string ListenAttachedVisibility
{
get { return (string)GetValue(SelectedValueBindingProperty); }
set { SetValue(SelectedValueBindingProperty, value); }
}

    public static readonly DependencyProperty ListenAttachedVisibilityProperty =
 DependencyProperty.Register("ListenAttachedVisibility", typeof(object), typeof(UserControl),
 new System.Windows.PropertyMetadata(null, new PropertyChangedCallback(OnVisibilityChanged)));

    private static void OnVisibilityChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {


        // call to instance method 
        ((DualLOV)d).OnVisibilityChanged(e);
    }
    protected virtual void OnVisibilityChanged(DependencyPropertyChangedEventArgs e)
    {
        ClearValues(e.NewValue);
    }

and then i made the binding:
Binding b = new Binding(“Visibility”) { Source = this };
this.SetBinding(ListenAttachedVisibilityProperty, b);

and the visibilty changed event worked fine also the memory leak disappeared.
thanks again.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T12:54:37+00:00Added an answer on May 25, 2026 at 12:54 pm

    Your original (pre-edit) post seems to indicate that you have a memory leak. I’m guessing the problem is you create a Dependency Properties as an instance variable. You never want to do this, and it will cause memory leaks.

    Edit:

    It’s not clear to me what you are trying to do. But your Dependency Property should be declared at the class level, and it should be static readonly.

    It makes sense that removing the callback fixes the leak, as the callback is a “short-lived subscriber” and the DP is a “long-lived publisher”. The DP is long-lived because the framework doesn’t know how to clean it up, as the framework expects the DP to be declared static readonly (I can’t explain why, that’s just the way it works in Silverlight).

    It looks like you are trying to do something with dynamic binding or notification. Whether what you are trying to do it possible or not is the subject of another question, but whatever the solution, it must be based on properly used (and declared) Dependency Properties.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Problem accessing user uploaded video in temporary memory So I've tried this
Using PyCrypto (although I've tried this in ObjC with OpenSSL bindings as well) :
Well I tried to figure out is this possible in any way. Here is
Well, I tried to ask this question as a comment on this question, but
I am a pretty good programmer(IMO only, of course. Know Python, Java well. Tried
Well, this is my first post here and really enjoying the site. I have
We've been debugging this JBoss server problem for quite a while. After about 10
I'm really pulling my hair out on this one, it seems that I'm having
If you ever tried to use MFC and OpenCV together, you would know this
I have tried to use this code in VS2008 (and may have included too

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.