Manual memory management is a bad idea, especially for COM objects. You can get an opinion on this from experts; a blog post from the Visual Studio team brings the point home pretty well.
Just in case, you still think this is a good idea, the Winforms team has already made a decision for you. An interface pointer wrapped by classes such as HtmlDocument, HtmlElement, HtmlWindow, HtmlElementCollection, etc., is a private variable of the class. You simply cannot get to it without breaking all the rules in the book.
Itβs not entirely impossible to have a problem, these objects of the shell class are quite small, so you may have a problem with the garbage collector, which does not work often enough to free the original COM objects. GC.Collect () is a reserve for this. Use it only when necessary.
source share