通过分配Image1.Ficture来清除图像:= nil;造成内存泄漏? [英] Does clearing an image by assigning Image1.Picture := nil; cause a memory leak?
问题描述
我在这里阅读过 http://delphi.about.com/od/ adimips2005 / qt / cleartimage.htm ,一种从TImage中清除图像的方法是将零分配给 .Picture
,如下所示:
Image1.Picture:= nil;
我只想确定...我猜,$ code Image1.Picture .loadFromFile(fileName)将分配一些内存,只需将其设置为nil,而不释放内存,将导致内存泄漏。
我对么?如果是这样,从TImage中卸载和清除图像的正确方式是什么?
TImage.Picture
setter is TImage.SetPicture()
在 ExtCtrls
单元,在 Graphics
单元中调用 TPicture.Assign()
,调用 TPicture。在分配新的
将释放现有的图形
之前,SetGraphic()图形
/ p>
所以使用
Image1.Picture:= nil;
最终会调用
Image1.Picture.SetGraphic(nil);
不会造成内存泄漏。
I have read here http://delphi.about.com/od/adptips2005/qt/cleartimage.htm that a way to clear an image from a TImage is to assign nil to .Picture
, like this:
Image1.Picture := nil;
I just want to be sure... I guess the Image1.Picture.loadFromFile(fileName)
will allocate some memory and simply setting it to nil, without freeing the memory, will lead to a memory leak.
Am I correct? If this is so, which is the "proper" way to unload and clear an image from a TImage?
The TImage.Picture
setter is TImage.SetPicture()
in the ExtCtrls
unit, which calls TPicture.Assign()
in the Graphics
unit, which calls TPicture.SetGraphic()
, which will free an existing Graphic
before assigning a new Graphic
.
So the usage of
Image1.Picture := nil;
Will ultimately call
Image1.Picture.SetGraphic(nil);
And will not cause any memory leak.
这篇关于通过分配Image1.Ficture来清除图像:= nil;造成内存泄漏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!