Board index » Visual Studio » Free memory used by Internet Explorer

Free memory used by Internet Explorer

Visual Studio32
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


-
 

Re:Free memory used by Internet Explorer

GC.Collect()



Regards - OHM





Andre Nogueira wrote:

Quote
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



--

Best Regards - OHM



O_H_M{at}BTInternet{dot}com





-

Re:Free memory used by Internet Explorer

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" rel="nofollow" target="_blank">discuss.develop.com/archives/wa.exe=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" <anog@netcabo.pt.NOSPAM>wrote in message

Quote
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









-

Re:Free memory used by Internet Explorer

It worked. thanks alot!! =)



Andre Nogueira



"Philip Rieck" <stuff@mckraken.com>wrote in message

Quote
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" rel="nofollow" target="_blank">discuss.develop.com/archives/wa.exe=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" <anog@netcabo.pt.NOSPAM>wrote in message

news:%23Dyznje2DHA.2680@TK2MSFTNGP11.phx.gbl...

>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

>

>









-

Re:Free memory used by Internet Explorer

* "Philip Rieck" <stuff@mckraken.com>scripsit:

Quote
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" rel="nofollow" target="_blank">discuss.develop.com/archives/wa.exe=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':



<msdn.microsoft.com/library/en-us/dllproc/base/setprocessworkingsetsize.asp>">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" rel="nofollow" target="_blank">support.microsoft.com/>



This behavior is by design and it doesn't make sense to worry about it.



--

Herfried K. Wagner [MVP]

<www.mvps.org/dotnet>">www.mvps.org/dotnet>

-

Re:Free memory used by Internet Explorer

* "Andre Nogueira" <anog@netcabo.pt.NOSPAM>scripsit:

Quote
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!).



--

Herfried K. Wagner [MVP]

<www.mvps.org/dotnet>">www.mvps.org/dotnet>

-