.net - How to release Excel application objects -


i have following code below in have class class level excel objects defined. when call excelmodule.test class these excel objects getting created , can see excel instance in task manager.

do have unload event class release these objects?

module excelmodule     public myrange excel.range     public mysheet excel.worksheet     public wb excel.workbook     public ex new excel.application      public sub test()      end sub end module 

while robert's suggestion of calling quit may work, it's flawed because if user has excel open before application creates application object, calling quit quit open instance of excel.

the issue com application doesn't know you're done reference excel application object. if goes out of scope , becomes eligible garbage collection/finalization, finalization won't occur immediately.

in rare circumstances, it's necessary call marshal.finalreleasecomobject on com object of time not necessary.

so while explicitly triggering garbage collection frowned upon, reality is necessary in .net/com interop. try (after ensuring you're no longer holding references excel objects...)

gc.collect(); gc.waitforpendingfinalizers(); 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -