<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-15">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>Hi all,</p>
<p>In one application I have a TImage where at different times,
depending on other conditions, I can either load the picture from
a file, or supply it a bitmap drawn by the program. As this
repeats quite a number of time, I must of course free my local
bitmap each time to avoid memory leaks.</p>
<p>All of this goes well, and heaptrc tells me "0 unfreed memory
blocks".</p>
<p>But if I happen to to copy the Timage bitmap to my local bitmap
for subsequent usage, any attempt to later free it both with
FreeAndNil and even with FreeImage causes a SIGSEV.</p>
<p> This occurs under Linux, both with Lazarus 1.8 and with 1.6, and
both with Gtk2 and Qt WS.<br>
</p>
<p>Here's a snippet of code used to show the issue:</p>
<pre><blockquote type="cite">procedure TForm1.Button1Click(Sender: TObject);
var
Filename: String;
begin
if OpenPictureDialog1.Execute then begin
// MyBitmap := Image1.Picture.Bitmap; <-------This causes a sigsev in FreeImage
Filename:= OpenPictureDialog1.FileName;
Image1.Picture.LoadFromFile(Filename);
If assigned(MyBitmap) then begin
MyBitmap.FreeImage;
FreeAndNil(MyBitmap);
end;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
If not Assigned(MyBitmap) then MyBitmap:= TBitmap.Create;
MyBitmap.Width:= Image1.Width;
MyBitmap.Height:= Image1.Height;
MyBitmap.Canvas.Brush.Color:= clNavy;
MyBitmap.Canvas.Brush.Style:= bsSolid;
MyBitmap.Canvas.FillRect(0,0,MyBitmap.Width,MyBitmap.Height);
Image1.Picture.Bitmap := MyBitmap;
//MyBitmap.FreeImage; Useless
FreeAndNil(MyBitmap);
end;
</blockquote>
</pre>
In my understanding this should not occur, because the underlying
bitmap should be properly reference counted, and the underlying
pixmap should be handled symmetrically.<br>
<br>
What's wrong with what I'm trying to do? What I'm missing?<br>
<br>
Giuliano<br>
<br>
</body>
</html>