Forum > Graphics
[SOLVED] TBitmap.Create causing Windows memory leak.
(1/1)
petevick:
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 [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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:
Delete line 5.
petevick:
--- Quote from: bytebites on April 19, 2023, 12:58:20 pm ---Delete line 5.
--- End quote ---
Brilliant, thanks bytebites ;)
wp:
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 [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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:
--- Quote from: wp on April 19, 2023, 01:03:50 pm ---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 [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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;
--- End quote ---
Noted, and thanks wp ;D
Navigation
[0] Message Index