How exactly GC.Collect() works??

  • Thread starter Thread starter vikaskuk
  • Start date Start date
V

vikaskuk

Hi,

I am using GC.Collect() in my application to clean the unmanaged
objects(Excel,Microsoft Project Plan objects) from memory.

My question is whenever I use GC.Collect()

Is operating system treats it as a command and starts collecting the
memory immediately?
or operating system treats it as request and It may or may not clean
the memory depending upon available memory to the system ?

Regards,
Vikas
 
GC.Collect doesn't instruct the OS to reclaim memory. Windows is COM based,
so as long as you have properly closed and released all your COM objects,
Windows will release that memory. What GC.Collect does is to force a
garbage collection on your application's memory space. Once again, properly
closing and releasing the COM objects will do this for you as the .NET
framework will automatically call GC.Collect when it needs to or when your
application goes idle.

Mike Ober.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top