473,468 Members | 4,655 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

help:nothing gets disposed

I have checked my program with memory profiler and it turns out that nothing
gets disposed.
As child form is opened and closed, it remains in memory.
Is there a way to clear memory manually? (GC.Collect() and similar have no
effect)
Nov 16 '05 #1
7 1250
Hi Barba,

You can't force GC to run when you want, and it doesn't run unless it
finds a reason to do so.
This may mean that objects may reside in memory even though you are
finished with them, until the memory usage reaches a certain limit.

You can try to use GC.Collect() to attempt to get it to run.

Happy coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #2
> This may mean that objects may reside in memory even though you are
finished with them, until the memory usage reaches a certain limit.
It grabs memory until there is no free memory to grab, then crahses (with
virtual memory disabled for testing)
You can try to use GC.Collect() to attempt to get it to run.


Does not do anything
It seems that garbage collector works fine as long as data is not displayed
on screen (5mb data array gets removed from memory, but if it was placed
into datagrid or rtbox, it will remain in memory).

This problem only occurs on child forms.

Also, this problem is not occuring on Win98SE (I use WinXP Pro)


Nov 16 '05 #3
That means you are still holding references to managed memory.
Just post a short but complete code sample that illustrates the problem.

Willy.

"Barba" <ba****@yahoo.com> wrote in message
news:c6**********@ls219.htnet.hr...
I have checked my program with memory profiler and it turns out that
nothing
gets disposed.
As child form is opened and closed, it remains in memory.
Is there a way to clear memory manually? (GC.Collect() and similar have no
effect)

Nov 16 '05 #4
> Just post a short but complete code sample that illustrates the problem.

Willy.


below is one of functions in main form which display child form.
when child form is closed, it remains in memory

public static void showCForm(int arg)
{

try
{

CForm childForm=null;
foreach(Form f in Brazda.Startup.ActiveForm.MdiChildren)
{
if(f is CForm)
{
switch (arg)
{
case 122:
if (f.Text=="122") //brzi najam
childForm = (CForm) f;
break;
case 123:
if (f.Text=="123") //izmjena najma
childForm = (CForm) f;
break;
case 207:
if (f.Text=="207") //PC Blagajna (robno)
childForm = (CForm) f;
break;
case 422:
if (f.Text=="422") //brzi najam marina brod+gosti
childForm = (CForm) f;
break;
case 423:
if (f.Text=="423") //izmjena najma marina brod+gosti
childForm = (CForm) f;
break;
case 722:
if (f.Text=="722") //brzi najam
childForm = (CForm) f;
break;
case 723:
if (f.Text=="723") //izmjena najma
childForm = (CForm) f;
break;
case 807:
if (f.Text=="807") //POS
childForm = (CForm) f;
break;
}
}
}
if( childForm != null)
{ //it is already open, just show it
childForm.Show();
childForm.Focus();

}
else
{ //load form
childForm = new CForm(arg);
childForm.MdiParent = Brazda.Startup.ActiveForm;
childForm.Show();
childForm.Focus();
}
}
catch//(Exception exp)
{
//MessageBox.Show(exp.Message);
}
}

Nov 16 '05 #5
Barba wrote:
This may mean that objects may reside in memory even though you are
finished with them, until the memory usage reaches a certain limit.


It grabs memory until there is no free memory to grab, then crahses (with
virtual memory disabled for testing)
You can try to use GC.Collect() to attempt to get it to run.


Does not do anything
It seems that garbage collector works fine as long as data is not
displayed on screen (5mb data array gets removed from memory, but if it
was placed into datagrid or rtbox, it will remain in memory).

This problem only occurs on child forms.

Also, this problem is not occuring on Win98SE (I use WinXP Pro)


Add

gc.WaitForPendingFinalizers()

after

gc.Collect()

--
W '04 <:> Open
Nov 16 '05 #6
Whoa what an advice. Of course I tried.
"Irritable Bowel Syndrome" <ja*****@earthlink.net> wrote in message
news:o1*****************@newsread1.news.pas.earthl ink.net...
Barba wrote:
This may mean that objects may reside in memory even though you are
finished with them, until the memory usage reaches a certain limit.


It grabs memory until there is no free memory to grab, then crahses (with virtual memory disabled for testing)
You can try to use GC.Collect() to attempt to get it to run.


Does not do anything
It seems that garbage collector works fine as long as data is not
displayed on screen (5mb data array gets removed from memory, but if it
was placed into datagrid or rtbox, it will remain in memory).

This problem only occurs on child forms.

Also, this problem is not occuring on Win98SE (I use WinXP Pro)


Add

gc.WaitForPendingFinalizers()

after

gc.Collect()

--
W '04 <:> Open

Nov 16 '05 #7
I asked for a short but complete sample, I don't see a Form.Close() call.

Willy.

"Barba" <ba****@yahoo.com> wrote in message
news:c7**********@ls219.htnet.hr...
Just post a short but complete code sample that illustrates the problem.

Willy.


below is one of functions in main form which display child form.
when child form is closed, it remains in memory

public static void showCForm(int arg)
{

try
{

CForm childForm=null;
foreach(Form f in Brazda.Startup.ActiveForm.MdiChildren)
{
if(f is CForm)
{
switch (arg)
{
case 122:
if (f.Text=="122") //brzi najam
childForm = (CForm) f;
break;
case 123:
if (f.Text=="123") //izmjena najma
childForm = (CForm) f;
break;
case 207:
if (f.Text=="207") //PC Blagajna (robno)
childForm = (CForm) f;
break;
case 422:
if (f.Text=="422") //brzi najam marina brod+gosti
childForm = (CForm) f;
break;
case 423:
if (f.Text=="423") //izmjena najma marina brod+gosti
childForm = (CForm) f;
break;
case 722:
if (f.Text=="722") //brzi najam
childForm = (CForm) f;
break;
case 723:
if (f.Text=="723") //izmjena najma
childForm = (CForm) f;
break;
case 807:
if (f.Text=="807") //POS
childForm = (CForm) f;
break;
}
}
}
if( childForm != null)
{ //it is already open, just show it
childForm.Show();
childForm.Focus();

}
else
{ //load form
childForm = new CForm(arg);
childForm.MdiParent = Brazda.Startup.ActiveForm;
childForm.Show();
childForm.Focus();
}
}
catch//(Exception exp)
{
//MessageBox.Show(exp.Message);
}
}

Nov 16 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Paul | last post by:
Trying to write a function that does the following: Joe gets 100 points for every 30 widgets he sells. So if he sells less than thirty he gets nothing. If he gets between 30 and 59 he gets...
8
by: MattP | last post by:
Ok, with the help of some examples found on the web and some minor modifications on our own, we have a simple and working encrypt and decrypt solution. It runs as a service, watches for files with...
5
by: DraguVaso | last post by:
Hi, I have made some classes, but when they are Finalized/Disposed or simply "MyClass = Nothing", I want to trigger this action, and ask to save unsaved changes. How should I do this? I'm...
16
by: David Ford | last post by:
I have a macro that I use across the board for freeing ram. I'd like to clean up my code so I don't get these warnings. #define sfree(x) _internal_sfree((void **)&x) #define _internal_sfree(x)...
6
by: Shane Saunders | last post by:
I have a menu option that loads a form and displays infomation. if you go to main form and try to load something else from that same menu, it does a check to see if the form in exist and then...
1
by: athos | last post by:
Dear All, I am following the msdn guidelines (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag2/html/paght000011.asp) trying the Health Monitoring module. Everything looks...
53
by: Hexman | last post by:
Hello All, I'd like your comments on the code below. The sub does exactly what I want it to do but I don't feel that it is solid as all. It seems like I'm using some VB6 code, .Net2003 code,...
9
by: Doug Glancy | last post by:
I got the following code from Francesco Balena's site, for disposing of Com objects: Sub SetNothing(Of T)(ByRef obj As T) ' Dispose of the object if possible If obj IsNot Nothing AndAlso...
32
by: =?Utf-8?B?U2l2?= | last post by:
I have a form that I programmatically generate some check boxes and labels on. Later on when I want to draw the form with different data I want to clear the previously created items and then put...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.