나는 메모리 누수를 추적하고 UserControl 파생 클래스에 할당 된 ToolTip으로 좁혔습니다. 이 같은UserControl에서 ToolTip 정리를 자동화하는 방법
도구 설명은 컨트롤의 생성자에서 할당에 할당되고 Load 이벤트에서 초기화 :
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");
}
}
컨트롤의 부모 컨트롤의 수명을 초과하는 수명을 가지고있다. 이 컨트롤은 즉시 생성되어 패널 컨트롤에 추가 된 다음 패널 컨트롤에서 제거됩니다.
툴팁에 대한 참조가 남아 있기 때문에 컨트롤의 Dispose 멤버가 호출되지 않은 것으로 나타났습니다. 종료 메서드를 호출
public void Shutdown()
{
toolTip1.RemoveAll();
}
누출을 제거하고 폐기 결국 호출됩니다
나는 이런 종료 방법을 추가했다.이 솔루션을 사용하는 사람은 누구나 종료시 Shutdown 메서드를 호출 한 사람이 기억해야합니다.
Shutdown 메서드를 명시 적으로 호출하지 않아도되도록 자동화 할 수있는 방법이 있는지 알고 싶습니다.
내 생각에 dispose를 호출하여 사용자 정의 컨트롤을 삭제하거나 툴바 종료 방법과 같은 기능을 제공하는 정리 기능이 필요할 수도 있습니다. 여기 – PRR
1. 봐 [http://stackoverflow.com/questions/672980/dispose-on-user-controls-really-meant-to-edit-the-designer-cs-file][1] [1] : http://stackoverflow.com/questions/672980/dispose-on-user-controls-really-meant-to-edit-the-designer-cs-file – VMykyt