views:

29

answers:

1

I'm trying to implement enhanced TabControl/TabPage classes, in order to achieve real TabVisible feature, since TabPage's Visible property doesn't work as expected.

I'm working with C# / WinForms / VS2005 / .Net FW 2.0; I've implemented the code this way:

http://csharp.pastebin.com/AUnzRQLw

And I've made a Form to test it, checking/unchecking CheckBoxes to show/hide some VisibleTabPage controls I've added (http..//csharp.pastebin.com/MkGJGx2G). But, after a certain number of clicks on CheckBoxes, in a random sequence, the application starts to allocate more and more memory, and use some considerable amount of CPU to show/hide TabPage controls.

Can anyone point me out where is the bug?

Thanks

+1  A: 

It's a bit too much code to wrestle through. I however see you use methods like Remove() and Clear() without you ever calling the Dispose() method for a tab page. These pages get "parked" and will keep using system resources. Run Taskmgr.exe, Processes tab, View + Select Columns, tick User32 objects. You'll probably see this number going up without bound as your code is leaking the Handle for the tab page and all of its controls.

Hans Passant
I've found the bug, it was the ArrayList that was initialized a lot of times. I've created a private ArrayList that I maintain for the whole lifetime of the TabControlEx object, and that solved the problem. Thanks anyway for the tip.
Alexandre