strange memory managment

  • Thread starter Thread starter Scott Underhill
  • Start date Start date
S

Scott Underhill

Hi All,

This might be something really straight fowward, but I have been debugging
my application.
I noticed some really unusual memory behaviour, after putting it through a
profile, I narrow
it down to the property AllowDrop = true.

I created some sample code, which simply adds a panel to a tab control 10
times, then removes
the control 10 times. If I have AllowDrop=true set the panel is never
destoryed in memory.

I am just interested in knowing why AllowDrop=true would stop the panel from
being destroyed ?

Thanks
Scott

------------- Sample Code -------------
for(int i=0;i<100;i++){

for(int j=0;j<10;j++){

TabPage page = new TabPage("we");

Panel a = new Panel();

a.AllowDrop = true;


page.Controls.Add(a );

this.tabControl1.TabPages.Add(page);

}

for(int k=0;k<10;k++){

this.tabControl1.TabPages[0].Controls.Clear();

this.tabControl1.TabPages.RemoveAt(0);

}


}

}
 
Scott Underhill said:
Hi All,

This might be something really straight fowward, but I have been debugging
my application.
I noticed some really unusual memory behaviour, after putting it through a
profile, I narrow
it down to the property AllowDrop = true.

I created some sample code, which simply adds a panel to a tab control 10
times, then removes
the control 10 times. If I have AllowDrop=true set the panel is never
destoryed in memory.

I am just interested in knowing why AllowDrop=true would stop the panel
from being destroyed ?

I would bet money that setting the control as a drop target registers it's
window handle, and a reference to the control object in a form-level
collection. The Form then has a reference to the control and will keep it
alive for the lifetime of the form.

David
 
Back
Top