Need a way to unload previously selected TabPage to release USER Objects











up vote
0
down vote

favorite












I have a C# WinForms TabControl, with many controls on each tab page. When you start, not many user objects are loaded, but as you switch tabs, it seems to load the tab with controls, and USER objects grows and grows, eventually hitting the limit and crashing the program. USER Objects is at its max setting in windows. At the moment, it can't be radically redesigned to use less controls, so that is a requirement here to maintain the same amount of controls on each tab.



I'm trying to see if there is a way to after switching tabs, to actually force unload the previous tab, so that it releases its user objects, then if switching back to that tab, everything seems normal and loads that one again (and unloads the previous one). Or some way to mimic this which actually releases USER objects.



I made a test program showing the issue, which can be easily recreated. C# WinForms, added 72 text boxes on each tab. When you start up to Tab 1, Task Manager shows 94 User Objects. When I click Tab 2, it shows 168. They never go lower. This happens without adding anything extra, no events, etc. Adding 2 more tabs, it goes to 315. So this is definitely something going on that is never unloaded, but only after click to tab. I need to find a way to lower USER objects on non-used tabs.










share|improve this question
























  • I think normally all tab content is initialized up front... are you dynamically loading content using an event handler when you change tabs? If you post some code, you will get a better answer.
    – Elemental Pete
    Nov 7 at 16:46










  • Your program crashes when you created 10,000 controls. That is an enormous number, a tabcontrol with that many of them stopped being usable a long time ago. Crystal ball says that the real problem is that you remove controls with Controls.Clear() or Controls.Remove(). Which is incorrect, you must call their Dispose() method when you do this. Get rid of an entire tab with all its controls by calling the TabPage.Dispose() method.
    – Hans Passant
    Nov 7 at 16:49










  • It's not 10,000 (actually it's set to 18,000), it's much less, some controls are really multiple controls, etc or use more than one user object by default. I didn't think it would add on tab switch, but I will investigate and see if there is something causing many additional user objects that can be removed on tab switch. Will write a little test program to see if I can recreate, didn't realize all tabs were preloaded. I wonder if there is a good way to profile what controls creates user objects in Visual Studio.
    – Mary Ellen Bench
    Nov 7 at 17:25












  • I made a test program showing the issue. C# WinForms, added 72 text boxes on each tab. When you start up to Tab 1, Task Manager shows 94 User Objects. When I click Tab 2, it shows 168. They never go lower. So does this help anyone with my question? This happens without adding anything extra, no events, etc. Adding 2 more tabs, it goes to 315 only after clicking all tabs. So this is definitely something going on that is never unloaded, but only after click to tab.
    – Mary Ellen Bench
    Nov 7 at 17:32








  • 1




    So you need to "dispose" the controls when the tab is de-selected, but put them back (with their events) when the tab is re-selected. I guess you can try to move all the tab content into a UserControl, then dispose and add the control during those tab events.
    – LarsTech
    Nov 7 at 18:17















up vote
0
down vote

favorite












I have a C# WinForms TabControl, with many controls on each tab page. When you start, not many user objects are loaded, but as you switch tabs, it seems to load the tab with controls, and USER objects grows and grows, eventually hitting the limit and crashing the program. USER Objects is at its max setting in windows. At the moment, it can't be radically redesigned to use less controls, so that is a requirement here to maintain the same amount of controls on each tab.



I'm trying to see if there is a way to after switching tabs, to actually force unload the previous tab, so that it releases its user objects, then if switching back to that tab, everything seems normal and loads that one again (and unloads the previous one). Or some way to mimic this which actually releases USER objects.



I made a test program showing the issue, which can be easily recreated. C# WinForms, added 72 text boxes on each tab. When you start up to Tab 1, Task Manager shows 94 User Objects. When I click Tab 2, it shows 168. They never go lower. This happens without adding anything extra, no events, etc. Adding 2 more tabs, it goes to 315. So this is definitely something going on that is never unloaded, but only after click to tab. I need to find a way to lower USER objects on non-used tabs.










share|improve this question
























  • I think normally all tab content is initialized up front... are you dynamically loading content using an event handler when you change tabs? If you post some code, you will get a better answer.
    – Elemental Pete
    Nov 7 at 16:46










  • Your program crashes when you created 10,000 controls. That is an enormous number, a tabcontrol with that many of them stopped being usable a long time ago. Crystal ball says that the real problem is that you remove controls with Controls.Clear() or Controls.Remove(). Which is incorrect, you must call their Dispose() method when you do this. Get rid of an entire tab with all its controls by calling the TabPage.Dispose() method.
    – Hans Passant
    Nov 7 at 16:49










  • It's not 10,000 (actually it's set to 18,000), it's much less, some controls are really multiple controls, etc or use more than one user object by default. I didn't think it would add on tab switch, but I will investigate and see if there is something causing many additional user objects that can be removed on tab switch. Will write a little test program to see if I can recreate, didn't realize all tabs were preloaded. I wonder if there is a good way to profile what controls creates user objects in Visual Studio.
    – Mary Ellen Bench
    Nov 7 at 17:25












  • I made a test program showing the issue. C# WinForms, added 72 text boxes on each tab. When you start up to Tab 1, Task Manager shows 94 User Objects. When I click Tab 2, it shows 168. They never go lower. So does this help anyone with my question? This happens without adding anything extra, no events, etc. Adding 2 more tabs, it goes to 315 only after clicking all tabs. So this is definitely something going on that is never unloaded, but only after click to tab.
    – Mary Ellen Bench
    Nov 7 at 17:32








  • 1




    So you need to "dispose" the controls when the tab is de-selected, but put them back (with their events) when the tab is re-selected. I guess you can try to move all the tab content into a UserControl, then dispose and add the control during those tab events.
    – LarsTech
    Nov 7 at 18:17













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have a C# WinForms TabControl, with many controls on each tab page. When you start, not many user objects are loaded, but as you switch tabs, it seems to load the tab with controls, and USER objects grows and grows, eventually hitting the limit and crashing the program. USER Objects is at its max setting in windows. At the moment, it can't be radically redesigned to use less controls, so that is a requirement here to maintain the same amount of controls on each tab.



I'm trying to see if there is a way to after switching tabs, to actually force unload the previous tab, so that it releases its user objects, then if switching back to that tab, everything seems normal and loads that one again (and unloads the previous one). Or some way to mimic this which actually releases USER objects.



I made a test program showing the issue, which can be easily recreated. C# WinForms, added 72 text boxes on each tab. When you start up to Tab 1, Task Manager shows 94 User Objects. When I click Tab 2, it shows 168. They never go lower. This happens without adding anything extra, no events, etc. Adding 2 more tabs, it goes to 315. So this is definitely something going on that is never unloaded, but only after click to tab. I need to find a way to lower USER objects on non-used tabs.










share|improve this question















I have a C# WinForms TabControl, with many controls on each tab page. When you start, not many user objects are loaded, but as you switch tabs, it seems to load the tab with controls, and USER objects grows and grows, eventually hitting the limit and crashing the program. USER Objects is at its max setting in windows. At the moment, it can't be radically redesigned to use less controls, so that is a requirement here to maintain the same amount of controls on each tab.



I'm trying to see if there is a way to after switching tabs, to actually force unload the previous tab, so that it releases its user objects, then if switching back to that tab, everything seems normal and loads that one again (and unloads the previous one). Or some way to mimic this which actually releases USER objects.



I made a test program showing the issue, which can be easily recreated. C# WinForms, added 72 text boxes on each tab. When you start up to Tab 1, Task Manager shows 94 User Objects. When I click Tab 2, it shows 168. They never go lower. This happens without adding anything extra, no events, etc. Adding 2 more tabs, it goes to 315. So this is definitely something going on that is never unloaded, but only after click to tab. I need to find a way to lower USER objects on non-used tabs.







c# .net winforms tabcontrol






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 7 at 17:35

























asked Nov 7 at 16:44









Mary Ellen Bench

1691221




1691221












  • I think normally all tab content is initialized up front... are you dynamically loading content using an event handler when you change tabs? If you post some code, you will get a better answer.
    – Elemental Pete
    Nov 7 at 16:46










  • Your program crashes when you created 10,000 controls. That is an enormous number, a tabcontrol with that many of them stopped being usable a long time ago. Crystal ball says that the real problem is that you remove controls with Controls.Clear() or Controls.Remove(). Which is incorrect, you must call their Dispose() method when you do this. Get rid of an entire tab with all its controls by calling the TabPage.Dispose() method.
    – Hans Passant
    Nov 7 at 16:49










  • It's not 10,000 (actually it's set to 18,000), it's much less, some controls are really multiple controls, etc or use more than one user object by default. I didn't think it would add on tab switch, but I will investigate and see if there is something causing many additional user objects that can be removed on tab switch. Will write a little test program to see if I can recreate, didn't realize all tabs were preloaded. I wonder if there is a good way to profile what controls creates user objects in Visual Studio.
    – Mary Ellen Bench
    Nov 7 at 17:25












  • I made a test program showing the issue. C# WinForms, added 72 text boxes on each tab. When you start up to Tab 1, Task Manager shows 94 User Objects. When I click Tab 2, it shows 168. They never go lower. So does this help anyone with my question? This happens without adding anything extra, no events, etc. Adding 2 more tabs, it goes to 315 only after clicking all tabs. So this is definitely something going on that is never unloaded, but only after click to tab.
    – Mary Ellen Bench
    Nov 7 at 17:32








  • 1




    So you need to "dispose" the controls when the tab is de-selected, but put them back (with their events) when the tab is re-selected. I guess you can try to move all the tab content into a UserControl, then dispose and add the control during those tab events.
    – LarsTech
    Nov 7 at 18:17


















  • I think normally all tab content is initialized up front... are you dynamically loading content using an event handler when you change tabs? If you post some code, you will get a better answer.
    – Elemental Pete
    Nov 7 at 16:46










  • Your program crashes when you created 10,000 controls. That is an enormous number, a tabcontrol with that many of them stopped being usable a long time ago. Crystal ball says that the real problem is that you remove controls with Controls.Clear() or Controls.Remove(). Which is incorrect, you must call their Dispose() method when you do this. Get rid of an entire tab with all its controls by calling the TabPage.Dispose() method.
    – Hans Passant
    Nov 7 at 16:49










  • It's not 10,000 (actually it's set to 18,000), it's much less, some controls are really multiple controls, etc or use more than one user object by default. I didn't think it would add on tab switch, but I will investigate and see if there is something causing many additional user objects that can be removed on tab switch. Will write a little test program to see if I can recreate, didn't realize all tabs were preloaded. I wonder if there is a good way to profile what controls creates user objects in Visual Studio.
    – Mary Ellen Bench
    Nov 7 at 17:25












  • I made a test program showing the issue. C# WinForms, added 72 text boxes on each tab. When you start up to Tab 1, Task Manager shows 94 User Objects. When I click Tab 2, it shows 168. They never go lower. So does this help anyone with my question? This happens without adding anything extra, no events, etc. Adding 2 more tabs, it goes to 315 only after clicking all tabs. So this is definitely something going on that is never unloaded, but only after click to tab.
    – Mary Ellen Bench
    Nov 7 at 17:32








  • 1




    So you need to "dispose" the controls when the tab is de-selected, but put them back (with their events) when the tab is re-selected. I guess you can try to move all the tab content into a UserControl, then dispose and add the control during those tab events.
    – LarsTech
    Nov 7 at 18:17
















I think normally all tab content is initialized up front... are you dynamically loading content using an event handler when you change tabs? If you post some code, you will get a better answer.
– Elemental Pete
Nov 7 at 16:46




I think normally all tab content is initialized up front... are you dynamically loading content using an event handler when you change tabs? If you post some code, you will get a better answer.
– Elemental Pete
Nov 7 at 16:46












Your program crashes when you created 10,000 controls. That is an enormous number, a tabcontrol with that many of them stopped being usable a long time ago. Crystal ball says that the real problem is that you remove controls with Controls.Clear() or Controls.Remove(). Which is incorrect, you must call their Dispose() method when you do this. Get rid of an entire tab with all its controls by calling the TabPage.Dispose() method.
– Hans Passant
Nov 7 at 16:49




Your program crashes when you created 10,000 controls. That is an enormous number, a tabcontrol with that many of them stopped being usable a long time ago. Crystal ball says that the real problem is that you remove controls with Controls.Clear() or Controls.Remove(). Which is incorrect, you must call their Dispose() method when you do this. Get rid of an entire tab with all its controls by calling the TabPage.Dispose() method.
– Hans Passant
Nov 7 at 16:49












It's not 10,000 (actually it's set to 18,000), it's much less, some controls are really multiple controls, etc or use more than one user object by default. I didn't think it would add on tab switch, but I will investigate and see if there is something causing many additional user objects that can be removed on tab switch. Will write a little test program to see if I can recreate, didn't realize all tabs were preloaded. I wonder if there is a good way to profile what controls creates user objects in Visual Studio.
– Mary Ellen Bench
Nov 7 at 17:25






It's not 10,000 (actually it's set to 18,000), it's much less, some controls are really multiple controls, etc or use more than one user object by default. I didn't think it would add on tab switch, but I will investigate and see if there is something causing many additional user objects that can be removed on tab switch. Will write a little test program to see if I can recreate, didn't realize all tabs were preloaded. I wonder if there is a good way to profile what controls creates user objects in Visual Studio.
– Mary Ellen Bench
Nov 7 at 17:25














I made a test program showing the issue. C# WinForms, added 72 text boxes on each tab. When you start up to Tab 1, Task Manager shows 94 User Objects. When I click Tab 2, it shows 168. They never go lower. So does this help anyone with my question? This happens without adding anything extra, no events, etc. Adding 2 more tabs, it goes to 315 only after clicking all tabs. So this is definitely something going on that is never unloaded, but only after click to tab.
– Mary Ellen Bench
Nov 7 at 17:32






I made a test program showing the issue. C# WinForms, added 72 text boxes on each tab. When you start up to Tab 1, Task Manager shows 94 User Objects. When I click Tab 2, it shows 168. They never go lower. So does this help anyone with my question? This happens without adding anything extra, no events, etc. Adding 2 more tabs, it goes to 315 only after clicking all tabs. So this is definitely something going on that is never unloaded, but only after click to tab.
– Mary Ellen Bench
Nov 7 at 17:32






1




1




So you need to "dispose" the controls when the tab is de-selected, but put them back (with their events) when the tab is re-selected. I guess you can try to move all the tab content into a UserControl, then dispose and add the control during those tab events.
– LarsTech
Nov 7 at 18:17




So you need to "dispose" the controls when the tab is de-selected, but put them back (with their events) when the tab is re-selected. I guess you can try to move all the tab content into a UserControl, then dispose and add the control during those tab events.
– LarsTech
Nov 7 at 18:17

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53194026%2fneed-a-way-to-unload-previously-selected-tabpage-to-release-user-objects%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53194026%2fneed-a-way-to-unload-previously-selected-tabpage-to-release-user-objects%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud

Zucchini