About the child form PropertyStore and MDI

This is a .net WinForm question about configuring MDI.

When the main form creates an MDI child form, the PropertyStore main form contains a link to the MDI child form. I wonder if this will cause the child form to be alive even if it is closed. If so, what should I do if you delete the child form to remove this link?

The detailed form is called according to the sample code:

 //The code is in the main form. var f = new FormMDIChild(); f.MdiParent = this; f.Show(); 
+3
memory-leaks
source share
2 answers

For the record, the solution proposed in this article works (albeit a bit risky). However, the leak also disappears if you open and close another child form, it seems that the MDI parent only leaks the last child opened.

If you want to fix the leak using the work specified in the link, just override the MDMarent OnMdiChildActivate method ...

 protected override void OnMdiChildActivate(EventArgs e) { base.OnMdiChildActivate(e); typeof(Form).InvokeMember("FormerlyActiveMdiChild", BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.NonPublic, null, this, new object[] { null }); } 
+7
source share

I have the same problem. I found this post discussing the problem and suggesting a solution, but I'm not sure that this property has been removed in the latest service packs, as I seem to be unable to find the property using reflection, so the solution does not work for me. I will look back and let me know if I will find another solution.

+2
source share

All Articles