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

  • SEARCH
  • Home
  • 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 3875326
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:15:16+00:00 2026-05-19T22:15:16+00:00

Our application adds and removes WPF (4.0) UserControls from it’s main window, and we’ve

  • 0

Our application adds and removes WPF (4.0) UserControls from it’s main window, and we’ve noticed that they are not getting Garbage Collected (via WeakReferences that never return null). It seems that if a UserControl has a binding this occurs, even if the control was never added to the tree. The simplest reproduction in a console application follows:

Main Program

class Program
{
    [STAThread]
    static void Main(string[] args)
    {
        var obj = GetObj();
        var ctl = GetCtl();
        for (int x = 0; x < 4; x++)
        {
            GC.Collect();
            Thread.Sleep(1000);
        }
        bool objAlive = obj.IsAlive;
        bool ctlAlive = ctl.IsAlive;
        Console.WriteLine(objAlive + "-" + ctlAlive);
        Console.ReadLine();
    }

    private static WeakReference GetObj()
    {
        return new WeakReference(new object());
    }

    private static WeakReference GetCtl()
    {
        return new WeakReference(new MyCtl());
    }
}

MyCtl User Control (Code behind is standard and has not been modified

<UserControl <!--Snip Default Namespaces-->>
    <TextBlock Text="{Binding Blah}" />
</UserControl>

objAlive is false, but ctlAlive is true. If the Binding is removed from the UserControl XAML, both are false. If I connect a memory profiler, MyCtl is still hanging around, but I can’t figure out what is referencing it (tips on how to find this using the jetBrains one is appreciated).

Is this expected behaviour or do I need to do more to clean up my WPF UserControls?

  • 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-19T22:15:17+00:00Added an answer on May 19, 2026 at 10:15 pm

    Depends on what you are binding to.

    This could be a known issue: http://support.microsoft.com/kb/938416

    Are you binding to a custom class? Have you implemented INotifyPropertyChanged or made a DependencyProperty?

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

Sidebar

Related Questions

Our application runs off MySQL, but a client has another application that requires SQL.
We have a medium sized application that depends on several usercontrols, namely: A tablelayout
Our application is occasionally getting a BUS_ADRALN. Looking at the crash log it shows
Our application is mining names from people using Twitter to login. Twitter is providing
Our application adds objects to the cache using the following int cacheTimeout = 5;
I am developing an application that adds a tab to a specific fan page
Our application is interfacing with a lot of web services these days. We have
Our application is a hybrid Win32 unmanaged application and a .NET 2.0 managed application.
Our application has a file format similar to the OpenDocument file format (see http://en.wikipedia.org/wiki/OpenDocument
Our application is structured something like: UI <--> REST API <--> Workflow <--> Business

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.