delphiihtmldocument2

Free memory for IHTMLDocument2


I'm using IHTMLDocument2 as this:

var
  doc: OleVariant;

doc:= coHTMLDocument.Create as IHTMLDocument2;
doc:= CreateComObject(Class_HTMLDOcument) as IHTMLDocument2;
doc.write(html);
doc.close;
(...)

How should I dispose of "doc" properly?


Solution

  • You don't have to do anything to dispose of it, if doc is a local variable (within a procedure or function). IHTMLDocument2 is an interface and is reference counted; the compiler will make sure it's released when it goes out of scope.

    If it's not a local variable, you can simply set it to null or Unassigned, as in doc := Unassigned; which will decrement the reference count.