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 9132347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:17:50+00:00 2026-06-17T08:17:50+00:00

I have a subclass of System::Windows::Forms::UserControl which allocates some unmanaged resources which have to

  • 0

I have a subclass of System::Windows::Forms::UserControl which allocates some unmanaged resources which have to be released in the destructor. It is used in WPF application through WindowsFormsHost. If the control is shown at least once in the application it’s destructor will be called. But if the instance of the control is created but never shown only finalizer gets called.

Why does that happen?

  • 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-06-17T08:17:51+00:00Added an answer on June 17, 2026 at 8:17 am

    Calling IDisposable::Dispose() invokes your ~destructor. It is an optional call, it must be made explicitly by other code. You’ll get it when you add your control to the Controls collection of a container (like a Form or Panel) and the container gets properly disposed. Which in general is automatic when the user closes a window by clicking the close button.

    Lots of scenarios where that “automatic” doesn’t work. The notorious ones is when you remove a control yourself by calling the Controls::Remove/At() or the Controls::Clear() method. It certainly won’t be automatic when you just used gcnew to create the instance but then never actually made it visible by adding it to a container control. The ControlsCollection class can’t do its job.

    The optional call needs to be backed up by the guaranteed call. You must always implement the !finalizer when unmanaged resources need to be released. So they can never be leaked when the code that uses your control skips the optional call, for whatever reason. That !finalizer will be called, just later.

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

Sidebar

Related Questions

I am trying to subclass System.Windows.Controls.DataGrid in order to add special commands to which
I have a System.Windows.Controls.Image which is decorated with a couple of adorners. Now I
Class A has a Form1 (subclass of System.Windows.Forms.Form) member. class A { Form1 form;
I have subclass of UINavigationBar . @interface MyNavigationBar : UINavigationBar Made some changes and
HI All. I have subclass of UIScrollView. IN this class I have added some
I have a subclass of JLabel that forms a component of my GUI. I
I have a base class called Geometry from which there exists a subclass Sphere
I have a subclass of TabItem as follows, for which I'm trying to set
I have the following simple TextBox subclass , which adds one dependency property (OutputIndex):
I have subclassed a system class (UINavigationBar, to be specific) to add some specific

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.