[SOLVED] TBitmap.Create causing Windows memory leak. lazarus / 39-Graphics ---------------------------------------------------------------------- petevick · 2023-04-19 10:53 I'm using the following code to create a bitmap of the app, but on closing the app I get a memory leak report indicating that the problem is with the imgWindow := TBitmap.Create; I've tried to change imgWindow.Free; to imgWindow.Destroy; but still get the memory leak. Any help would be gratefully received. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button2Click(Sender: TObject);var  imgWindow: TBitmap;begin  imgWindow := TBitmap.Create;  try    imgWindow := Form1.GetFormImage;    imgWindow.SaveToFile('c:\FormImage.bmp');  finally    imgWindow.Free;  end;end; ---------------------------------------------------------------------- bytebites · 2023-04-19 10:58 Delete line 5. ---------------------------------------------------------------------- petevick · 2023-04-19 11:00 Quote from: bytebites on April 19, 2023, 12:58:20 pmDelete line 5. Brilliant, thanks bytebites ---------------------------------------------------------------------- wp · 2023-04-19 11:03 But don't use Form1 in the code of the class TForm1. This way your code works only when the instance of TForm1 that you created is named "Form1". Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button2Click(Sender: TObject);var  imgWindow: TBitmap;begin  imgWindow := GetFormImage;  // wrong: Form1.GetFormImage;  try    imgWindow.SaveToFile('c:\FormImage.bmp');  finally    imgWindow.Free;  end;end; ---------------------------------------------------------------------- petevick · 2023-04-19 11:08 Quote from: wp on April 19, 2023, 01:03:50 pmBut don't use Form1 in the code of the class TForm1. This way your code works only when the instance of TForm1 that you created is named "Form1". Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button2Click(Sender: TObject);var  imgWindow: TBitmap;begin  imgWindow := GetFormImage;  // wrong: Form1.GetFormImage;  try    imgWindow.SaveToFile('c:\FormImage.bmp');  finally    imgWindow.Free;  end;end;Noted, and thanks wp