Clears the image by assigning Image1.Picture: = nil; cause a memory leak?

I read here http://delphi.about.com/od/adptips2005/qt/cleartimage.htm that the way to clear the image from TImage is to assign nil to .Picture like this

 Image1.Picture := nil; 

I just want to be sure ... I think that Image1.Picture.loadFromFile(fileName) will allocate some memory and just set it to zero without freeing up memory will cause a memory leak.

Am I right? If so, what is the β€œright” way to upload and clear images from TImage?

+6
source share
1 answer

Installer TImage.Picture TImage.SetPicture() in the ExtCtrls module, which calls TPicture.Assign() in the Graphics module, which calls TPicture.SetGraphic() , which will free the existing Graphic before assigning a new Graphic .

Thus using

 Image1.Picture := nil; 

Will ultimately cause

 Image1.Picture.SetGraphic(nil); 

And will not lead to a memory leak.

+11
source

Source: https://habr.com/ru/post/970169/


All Articles