Use CopyRect to transfer part of the image on another canvas to the image of the TCanvas object. Dest specifies the rectangle on the canvas where the source image will be copied. The Canvas parameter specifies the canvas with the source image. Source specifies a rectangle bounding the portion of the source canvas that will be copied.As i understood it: Your Destination is B, your Source is C
B.Canvas.CopyRect(Rect(0,0,319,239),C.Canvas,Rect(0,0,319,239));
B := TBitMap.Create;;;;;getmem_incr;738
073068C4;TBitmap;getmem;size;72;getmem_incr;739
07306C04;TSharedBitmap;getmem;size;124;getmem_incr;740
C := TCursorImage.Create;;;;;getmem_incr;740
07306D0C;TCursorImage;getmem;size;72;getmem_incr;741
072FD4D4;TSharedCursorImage;getmem;size;24;getmem_incr;742
07306DDC;TFPList;getmem;size;16;getmem_incr;743
B.SetSize(320,240);;;;;getmem_incr;743
B.Canvas.CopyRect(...);;;;;getmem_incr;743
07306E74;TBitmapCanvas;getmem;size;172;getmem_incr;744
07306FAC;TList;getmem;size;16;getmem_incr;745
07307044;TFont;getmem;size;108;getmem_incr;746
0730713C;memory;getmem;size;32;getmem_incr;747
073071E4;memory;getmem;size;16;getmem_incr;748
0730727C;TPen;getmem;size;92;getmem_incr;749
07307364;TBrush;getmem;size;204;getmem_incr;750
073074BC;TRegion;getmem;size;32;getmem_incr;751
09BD00B4;memory;getmem;size;230400;getmem_incr;752
07307564;memory;getmem;size;9600;getmem_incr;753
09BD00B4;memory;freemem;size;230400;getmem_incr;752
07307564;memory;freemem;size;9600;getmem_incr;753
C.Assign(B);;;;;getmem_incr;753
07307564;TCursorImageImage;getmem;size;128;getmem_incr;754
0730766C;memory;getmem;size;16;getmem_incr;755
09BD00B4;memory;getmem;size;230400;getmem_incr;756
07307704;memory;getmem;size;9600;getmem_incr;757
07309D0C;memory;getmem;size;9600;getmem_incr;758
07307704;memory;freemem;size;9600;getmem_incr;757
09C0853C;TCursorImageImage;getmem;size;128;getmem_incr;759
09C08644;memory;getmem;size;230400;getmem_incr;760
07307704;memory;getmem;size;9600;getmem_incr;761
0730C314;memory;getmem;size;9600;getmem_incr;762
07307704;memory;freemem;size;9600;getmem_incr;761
07307704;memory;getmem;size;9600;getmem_incr;763
0730E91C;memory;getmem;size;9600;getmem_incr;764
07307704;memory;freemem;size;9600;getmem_incr;763
07307704;memory;getmem;size;9600;getmem_incr;765
0730C314;memory;freemem;size;9600;getmem_incr;762
07307564;TCursorImageImage;freemem;size;128;getmem_incr;754
B.Free;;;;;getmem_incr;765
09BD00B4;memory;freemem;size;230400;getmem_incr;756
07309D0C;memory;freemem;size;9600;getmem_incr;758
07306C04;TSharedBitmap;freemem;size;124;getmem_incr;740
073074BC;TRegion;freemem;size;32;getmem_incr;751
073071E4;memory;freemem;size;16;getmem_incr;748
0730713C;memory;freemem;size;32;getmem_incr;747
07307044;TFont;freemem;size;108;getmem_incr;746
07307364;TBrush;freemem;size;204;getmem_incr;750
0730727C;TPen;freemem;size;92;getmem_incr;749
07306FAC;TList;freemem;size;16;getmem_incr;745
07306E74;TBitmapCanvas;freemem;size;172;getmem_incr;744
073068C4;TBitmap;freemem;size;72;getmem_incr;739
C.Free;;;;;getmem_incr;765
09C08644;memory;freemem;size;230400;getmem_incr;760
07307704;memory;freemem;size;9600;getmem_incr;765
09C0853C;TCursorImageImage;freemem;size;128;getmem_incr;759
0730766C;memory;freemem;size;16;getmem_incr;755
07306DDC;TFPList;freemem;size;16;getmem_incr;743
072FD4D4;TSharedCursorImage;freemem;size;24;getmem_incr;742
07306D0C;TCursorImage;freemem;size;72;getmem_incr;741
Heap dump by heaptrc unit
Max trace depth : 16
775 memory blocks allocated : 2309708/2310520
774 memory blocks freed : 2300108/2300920
1 unfreed memory blocks : 9600
Call trace for block $0730E91C size 9600 getmem_incr=764
$00410A26 line 280 of ../inc/heap.inc
$00459183 line 306 of graphtype.pp
$0054356A line 1322 of win32/win32proc.pp
$004DF582 line 1064 of win32/win32lclintf.inc
$004AA150 line 172 of include/lclintf.inc
$004A2B68 line 444 of include/icon.inc
$004A28CF line 383 of include/icon.inc
$0042BB17 line 71 of frmdebugleaks_1.pas
$004F8128 line 2995 of include/control.inc
$0050EB6D line 55 of include/buttoncontrol.inc
$0050F18D line 169 of include/buttons.inc
$0050EA99 line 21 of include/buttoncontrol.inc
$004F3652 line 78 of include/control.inc
$004F71B0 line 2313 of include/control.inc
$004ED9F1 line 5467 of include/wincontrol.inc
$005505D9 line 112 of lclmessageglue.pas
In 61205 (lines 590 - 599), shouldn't the palette also be treated like Data and Mask.Yes palette is needed too. Done.
This procedure TRasterImage.LoadFromRawImage is called in Lazarus only once by \components\ideintf\imagelisteditor.pp in function CreateGlyphSplit (which itself is never called) so it is difficult to know, for example, what ADataOwner is supposed to mean.
That was the reason I suggested in https://forum.lazarus.freepascal.org/index.php/topic,45016.msg317235.html#msg317235 April 11, 2019, 03:43:45 pm a Patch using ReallocMem only when ADataOwner=False.
Please changed that, You have actually erased the pointers before calling the FreeData;
You just basically put it back to where it was...!
You need to clean up the existing img^.... You need to call FreeMem on those pointers.
DO NOT nil the pointers and then call Img^.FreeData because it will never free it!
In 61205 (lines 590 - 599), shouldn't the palette also be treated like Data and Mask.Yes palette is needed too. Done.
Since you didn't release any memory by setting the pointers to NIL, you have now recreated the memory
leak this all started from.
This only happens if both the img and Amage hold the same pointers, currently with simple do nothing project it appears that
img has NIL pointers already so you are not seeing the effects I am.
So what i can tell from... is this always final version?Actually 61210
https://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/lcl/include/rasterimage.inc?view=markup&root=lazarus&pathrev=61205
Ok, that is a bug. The problem existed before the leak fix. So it is unrelated.GetRawImagePtr can return a nil. Therefore if it's not checked, asking for img^.Data can be invalid (and even worse for all the other code that follows). It is always nil tested elsewhere in the code.
img := GetRawImagePtr;