Free memory used by Internet Explorer

  • Thread starter Thread starter Andre Nogueira
  • Start date Start date
A

Andre Nogueira

Hi there
In my VB.Net 2003 program, I use an Internet Explorer control (shdocvw.dll).
When I open the form containing the control, the program "eats" 20MB of RAM.
So far so good - IE itself uses about 20MB of ram to run.
The problem is that when I close the form (close it, not hide it).. the 20MB
are still used by the program!
The question is, how do I free them?
I tryed using
WbControl.Dispose()
WbControl = Nothing
on the Closing event of the form, but with no results.
Any ideas?
Thank you in advance! =)

Andre Nogueira
 
GC.Collect()

Regards - OHM


Andre said:
Hi there
In my VB.Net 2003 program, I use an Internet Explorer control
(shdocvw.dll). When I open the form containing the control, the
program "eats" 20MB of RAM. So far so good - IE itself uses about
20MB of ram to run.
The problem is that when I close the form (close it, not hide it)..
the 20MB are still used by the program!
The question is, how do I free them?
I tryed using
WbControl.Dispose()
WbControl = Nothing
on the Closing event of the form, but with no results.
Any ideas?
Thank you in advance! =)

Andre Nogueira
 
After you close this form, minimize your application's main form.. does the
memory go away? If so, you're probably seeing the memory "used" because the
application is keeping it in its working set. See this thread on the
dotnet-CLR archives:

[http://discuss.develop.com/archives/wa.exe?A2=ind0209C&L=DOTNET-CLR&D=0&I=-
3&P=1450]


Basically, you want to call the Win32 api function
SetProcessWorkingSetSize(hProcess, -1, -1).
If you're not familiar with P/Invoke, here's some code....

[DllImport("kernel32.dll")]
public static extern bool SetProcessWorkingSetSize( IntPtr proc, int min,
int max );
....
....
public static void ReclaimMemory()
{
System.GC.Collect();
System.GC.WaitForPendingFinalizers();
SetProcessWorkingSetSize( Process.GetCurrentProcess().Handle, -1, -1 );
}
 
It worked. thanks alot!! =)

Andre Nogueira

Philip Rieck said:
After you close this form, minimize your application's main form.. does
the
memory go away? If so, you're probably seeing the memory "used" because
the
application is keeping it in its working set. See this thread on the
dotnet-CLR archives:

[http://discuss.develop.com/archives/wa.exe?A2=ind0209C&L=DOTNET-CLR&D=0&I=-
3&P=1450]


Basically, you want to call the Win32 api function
SetProcessWorkingSetSize(hProcess, -1, -1).
If you're not familiar with P/Invoke, here's some code....

[DllImport("kernel32.dll")]
public static extern bool SetProcessWorkingSetSize( IntPtr proc, int min,
int max );
...
...
public static void ReclaimMemory()
{
System.GC.Collect();
System.GC.WaitForPendingFinalizers();
SetProcessWorkingSetSize( Process.GetCurrentProcess().Handle, -1, -1 );
}



Andre Nogueira said:
Hi there
In my VB.Net 2003 program, I use an Internet Explorer control (shdocvw.dll).
When I open the form containing the control, the program "eats" 20MB of RAM.
So far so good - IE itself uses about 20MB of ram to run.
The problem is that when I close the form (close it, not hide it).. the 20MB
are still used by the program!
The question is, how do I free them?
I tryed using
WbControl.Dispose()
WbControl = Nothing
on the Closing event of the form, but with no results.
Any ideas?
Thank you in advance! =)

Andre Nogueira
 
* "Philip Rieck said:
After you close this form, minimize your application's main form.. does the
memory go away? If so, you're probably seeing the memory "used" because the
application is keeping it in its working set. See this thread on the
dotnet-CLR archives:

[http://discuss.develop.com/archives/wa.exe?A2=ind0209C&L=DOTNET-CLR&D=0&I=-
3&P=1450]


Basically, you want to call the Win32 api function
SetProcessWorkingSetSize(hProcess, -1, -1).
If you're not familiar with P/Invoke, here's some code....

[DllImport("kernel32.dll")]
public static extern bool SetProcessWorkingSetSize( IntPtr proc, int min,
int max );
...
...
public static void ReclaimMemory()
{
System.GC.Collect();
System.GC.WaitForPendingFinalizers();
SetProcessWorkingSetSize( Process.GetCurrentProcess().Handle, -1, -1 );
}

Caution: This won't reduce the memory needed by the application in general:

The behavior caused by calling this function is not specific to .NET
applications only. It is a feature of the Windows/Explorer shell.

If an application is minimized, Windows removes the working set memory from
the application by calling the Win32 function 'SetProcessWorkingSetSize':

<http://msdn.microsoft.com/library/en-us/dllproc/base/setprocessworkingsetsize.asp>

Windows supposes that minimized applications will not be used for some time
and this memory will be made available to other processes.

When restoring the window the application gets the memory back:

<http://support.microsoft.com/?kbid=293215>

This behavior is by design and it doesn't make sense to worry about it.
 
* "Andre Nogueira said:
In my VB.Net 2003 program, I use an Internet Explorer control (shdocvw.dll).
When I open the form containing the control, the program "eats" 20MB of RAM.
So far so good - IE itself uses about 20MB of ram to run.
The problem is that when I close the form (close it, not hide it).. the 20MB
are still used by the program!
The question is, how do I free them?
I tryed using
WbControl.Dispose()
WbControl = Nothing
on the Closing event of the form, but with no results.
Any ideas?

Maybe you will have to work with
'System.Runtime.InteropServices.Marshal.ReleaseComObject' (untested!).
 
Back
Top