M
M
Maxim Tikhonov2016-02-26 17:23:35
Delphi
Maxim Tikhonov, 2016-02-26 17:23:35

How to free memory after using IHTMLElement?

The TImbeddedWB component is used to process web pages.
A long list of pages opens (about 10,000).
Further, work with the DOM model of the document is carried out using variables of the IHTMLElementCollection and IHTMLElement types.
One of the code snippets:

tmpInputs := WB.GetDocument.all.tags('input') as IHTMLElementCollection;
  for i := 0 to tmpInputs.Length - 1 do
  begin
    tmpElement := tmpInputs.item(i, 0) as IHTMLElement;
    tmpS := tmpElement.getAttribute('name', 0);
    if tmpS = 'searched_name' then
    begin
      tmpElement.setAttribute('value', 'somevalue', 0);
      tmpFound := True;
      break;
    end;
  end;

When processing a large number of pages, it eats up memory up to 1.5 GB and then gives a memory allocation error.
Tell me how to force free memory without closing the application and not waiting for 10 minutes?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xmoonlight, 2016-02-26
@xmoonlight

Why look for the field name through the collection, and even through the DOM?!
Can't you just parse pages using Source+Regex?
And already then - expose?
Don't use for on collections. Use while-do and free memory on each loop through the method of removing an object from the collection.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question