Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.
If you find these projects useful please consider becoming a sponsor with Patreon, GitHub or Liberapay.
I added FastMM4 to the uses clause in the simplebrowser2 and I didn't get memory leaks when I loaded a local html file.
If you search in google you will find that FastMM4 sometimes gives false positives, that is a false memory leak or memory access error.
However, I frequently use FastMM4 because it reports what was leaked and where was created.
In the end I found out the root cause of the memory leak.
My application was going through an infinite loop and in the end it was halted. The halt procedure didn't freed up the classes and that caused the memory leak.
However, the root cause was infinite memory loop caused by the code in TChromium.OnLoadEnd that was not working properly when the html loaded is from a local file. I have changed my source into:
procedure TForm1.Chromium1LoadEnd(Sender: TObject; const browser: ICefBrowser;
const frame: ICefFrame; httpStatusCode: Integer);
begin
FChromiumPageLoaded := False;
if frame = nil then
exit;
if Pos('file:///', Chromium1.DocumentURL) <> 0 then//this is the part that manages local files
begin
if httpStatusCode = -3 then
begin
if (browser <> nil) then
begin
//page is fully loaded now
end;
end;
end
else
begin// this part manages html from the web
if httpStatusCode = 200 then
begin
if (browser <> nil) and (frame.IsMain = True) then
begin
//page is fully loaded now
end;
end;
end;
end;
It seems it is working even if I am not sure this is the best way to handle it.
If you want to check for errors I would use the TChromium.OnLoadError event.
The errorCode parameter in that event gives more information.
errorCode can have all the ERR_* values defined in uCEFConstants.pas.
If you just want to know when the document has finished loading I would only check frame.IsMain in the TChromium.OnLoadEnd event.
procedure TForm1.Chromium1LoadEnd(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; httpStatusCode: Integer);
begin
if (frame <> nil) and frame.IsMain then
begin
//page is fully loaded now
end;
end;