I’ve a WPF app organized with tabs. I added a small button to each tabitem header that allow the user to close the tab.
When the user click on the small button, I remove the tabItem from the tabControl.
tabControl.Items.Remove(tabItem);
As result of this the tabItem dissapears, and that is fine, but here comes the problem:
The TabItem is not visible(good), but it still exists(bad). If I put a timer inside, the timer execucutes his Tick, and more important, if I’ve a datagrid with 200.000 records and I close the Tab, The garbage collector don’t release the memory as I expected.
I asked google about the problem and I’ve implemented some of the advices described. It didn’t work.
Can anyone help me? Thanks
This is what I’ve been using, and as far as I can tell it removes the tabitem from memory. The problem with leaving a timer inside of the tabitem, is that the GC won’t collect and dispose of it because it detects that the timer is still in use.
The Code:
The xaml:
Here’s the page with the Tabcontrol to add a tab: