Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to automate clean up of ToolTip in UserControl
    primarykey
    data
    text
    <p>I've been tracking down a memory leak and I've narrowed it down to a ToolTip that is allocated in a UserControl-derived class.</p> <p>The ToolTip is allocated in the allocated in the control's constructor and initialized in the Load event like this:</p> <pre><code>public class CommonProfile : System.Windows.Forms.UserControl { private ToolTip toolTip1; ... public CommonProfile() { InitializeComponent(); // Create the ToolTip and associate with the Form container. toolTip1 = new ToolTip(this.components); } private void CommonProfile_Load(object sender, System.EventArgs e) { // Set up the delays for the ToolTip. toolTip1.AutoPopDelay = 5000; toolTip1.InitialDelay = 1000; toolTip1.ReshowDelay = 500; // Force the ToolTip text to be displayed whether or not the form is active. toolTip1.ShowAlways = true; // Set up the ToolTip text toolTip1.SetToolTip(this.btnDeleteEntry, "Delete this Profile"); toolTip1.SetToolTip(this.lblProfileType, "Edit this Profile"); toolTip1.SetToolTip(this.lblProfileData, "Edit this Profile"); toolTip1.SetToolTip(this.picFlagForUpdate, "Toggle Flag for Update"); } } </code></pre> <p>The control's parent has a lifetime that exceeds the control's lifetime. This control is created on the fly and added to a panel control and then subsequently removed from the panel control.</p> <p>I found that the control's Dispose member was not getting called, apparently because references to the ToolTip remain.</p> <p>I added a Shutdown method like this:</p> <pre><code>public void Shutdown() { toolTip1.RemoveAll(); } </code></pre> <p>Calling the Shutdown method eliminates the leak and Dispose is eventually called.</p> <p>Unfortunately, this solution requires that whoever uses the control remembers to call the Shutdown method when they are finished with it.</p> <p>I'd like to know if there is some way that I can automate this so that it happens without the need to call the Shutdown method explicitly.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload