[Lazarus] A bitmap strange issue

Ondrej Pokorny lazarus at kluug.net
Sun Apr 22 13:49:25 CEST 2018


On 22.04.2018 12:38, Giuliano Colla via Lazarus wrote:
>
> Il 21/04/2018 18:07, Vojtěch Čihák via Lazarus ha scritto:
>
>> @ MyBitmap := Image1.Picture.Bitmap;
>>
>> This line only copies pointer, but Image1.Picture.Bitmap belongs to 
>> Image1 and it should care itself.
>>
>
> That's what I had guessed, but this means that there's a patent 
> inconsistency, as shown in the Button2Click part of my test:
>> Image1.Picture.Bitmap := MyBitmap; FreeAndNil(MyBitmap); 
> doesn't generate any error. If I don't free MyBitmap I see a memory 
> leakage in heaptrc.
>
> IOW
> Image1.Picture.Bitmap := MyBitmap;
> performs an implicit assign, creating a new Bitmap Object for Image1.
>
> The apparently symmetrical
> MyBitmap := Image1.Picture.Bitmap;
> just copies the pointer. Timage.Picture.GetBitmap and 
> TImage.Picture.SetBitmap do not follow the same logic.

Do you really mean that
Image1.Picture.Bitmap.SomeProperty := SomeValue;
should apply SomeProperty := SomeValue on a copied object of Bitmap and 
produce a memory leak?

And the same, that
Image1.Picture.Bitmap := Image2.Picture.Bitmap;
should produce a memory leak because of the temporary bitmap object?

...and taking it into detail because Picture is a property of TImage as 
well:
Image1.Picture.Bitmap := Image2.Picture.Bitmap;
would actually produce 3 memory leaks: 2x TPicture and 1x TBitmap.

Ondrej
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20180422/030e0b46/attachment.html>


More information about the Lazarus mailing list