Free memory for IHTMLDocument2

689 views Asked by At

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?

1

There are 1 answers

7
Ken White On BEST ANSWER

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.