Changeset 15


Ignore:
Timestamp:
Sep 22, 2014, 11:06:27 PM (10 years ago)
Author:
chronos
Message:
  • Added: Memory leaks reporting in debug mode.
  • Fixed: Various memory leaks in bitmap, color and colorformat classes.
Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/ColorFormats/UColorRGBA8.pas

    r14 r15  
    66
    77uses
    8   Classes, SysUtils, Graphics, UGraphic, UMemory;
     8  Classes, SysUtils, Graphics, UGraphic;
    99
    1010type
  • trunk/LibrePaint.lpi

    r14 r15  
    170170    </CodeGeneration>
    171171    <Linking>
     172      <Debugging>
     173        <UseHeaptrc Value="True"/>
     174      </Debugging>
    172175      <Options>
    173176        <Win32>
     
    176179      </Options>
    177180    </Linking>
     181    <Other>
     182      <CustomOptions Value="-dDEBUG"/>
     183    </Other>
    178184  </CompilerOptions>
    179185  <Debugging>
  • trunk/LibrePaint.lpr

    r13 r15  
    88  {$ENDIF}{$ENDIF}
    99  Interfaces, // this includes the LCL widgetset
    10   Forms, UCore, UGraphic, UProject, UMemory, UFormNew, UFormMain,
     10  SysUtils, Forms, UCore, UGraphic, UProject, UMemory, UFormNew, UFormMain,
    1111  UColorRGBA8, UColorGray8, UColorGray1, UColorGray4, UColorRGB565
    1212  { you can add units after this };
     
    1414{$R *.res}
    1515
     16{$IFDEF DEBUG}
     17const
     18  HeapTraceLog = 'heaptrclog.trc';
     19{$ENDIF}
     20
    1621begin
     22  {$IFDEF DEBUG}
     23  // Heap trace
     24  DeleteFile(ExtractFilePath(ParamStr(0)) + HeapTraceLog);
     25  SetHeapTraceOutput(ExtractFilePath(ParamStr(0)) + HeapTraceLog);
     26  {$ENDIF}
     27
    1728  RequireDerivedFormResource := True;
    1829  Application.Initialize;
  • trunk/UCore.lfm

    r13 r15  
    11object Core: TCore
    22  OnCreate = DataModuleCreate
     3  OnDestroy = DataModuleDestroy
    34  OldCreateOrder = False
    45  Height = 491
  • trunk/UCore.pas

    r13 r15  
    5757    procedure AZoomOutExecute(Sender: TObject);
    5858    procedure DataModuleCreate(Sender: TObject);
     59    procedure DataModuleDestroy(Sender: TObject);
    5960  private
    6061    { private declarations }
     
    9495end;
    9596
     97procedure TCore.DataModuleDestroy(Sender: TObject);
     98begin
     99  Project.Free;
     100end;
     101
    96102procedure TCore.Init;
    97103begin
    98104  // Set default
     105  Project.Bitmap.ColorFormat := ColorManager.Formats[0];
    99106  Project.Bitmap.Size := Point(200, 100);
    100107  if ColorManager.FormatCount > 0 then
     
    114121    Project.Bitmap.BackgroundColor.FromTColor(clBlack);
    115122    Project.Bitmap.DPI := FormNew.SpinEditDPI.Value;
    116     AZoomAll.Execute;;
     123    AZoomAll.Execute;
    117124  end;
    118125end;
  • trunk/UGraphic.pas

    r14 r15  
    5151    procedure Assign(Source: TGColor); virtual;
    5252    constructor Create;
     53    destructor Destroy; override;
    5354    property Channels[Channel: TGColorChannel]: TGColor read GetChannel;
    5455    property Data: TBitMemory read FData;
     
    339340  if FColorFormat = AValue then Exit;
    340341  FColorFormat := AValue;
    341   FData.Size := FColorFormat.BitDepth;
     342  if Assigned(FColorFormat) then
     343    FData.Size := FColorFormat.BitDepth
     344    else FData.Size := 0;
    342345end;
    343346
     
    406409begin
    407410  FData := TBitMemory.Create;
    408   Format := TGColorFormat.Create;
     411  Format := nil;
     412end;
     413
     414destructor TGColor.Destroy;
     415begin
     416  FData.Free;
     417  inherited Destroy;
    409418end;
    410419
     
    566575  X, Y: Integer;
    567576  Color: TGColor;
     577  Color2: TGColor;
    568578begin
    569579  for Y := 0 to Size.Y div 2 - 1 do
    570580    for X := 0 to Size.X - 1 do begin
    571581      Color := Pixels[X, Y];
    572       Pixels[X, Y] := Pixels[X, Size.Y - 1 - Y];
     582      Color2 := Pixels[X, Size.Y - 1 - Y];
     583      Pixels[X, Y] := Color2;
     584      Color2.Free;
    573585      Pixels[X, Size.Y - 1 - Y] := Color;
    574586      Color.Free;
     
    580592  X, Y: Integer;
    581593  Color: TGColor;
     594  Color2: TGColor;
    582595begin
    583596  for Y := 0 to Size.Y - 1 do
    584597    for X := 0 to Size.X div 2 - 1 do begin
    585598      Color := Pixels[X, Y];
    586       Pixels[X, Y] := Pixels[Size.X - 1 - X, Y];
     599      Color2 := Pixels[Size.X - 1 - X, Y];
     600      Pixels[X, Y] := Color2;
     601      Color2.Free;
    587602      Pixels[Size.X - 1 - X, Y] := Color;
    588603      Color.Free;
     
    608623  FData := TBitMemory.Create;
    609624  FBackgroundColor := TGColor.Create;
    610   ColorFormat := TGColorFormat.Create;
    611   FBackgroundColor.Format := ColorFormat;
    612   FBackgroundColor.FromTColor(clBlack);
     625  ColorFormat := nil;
    613626  Canvas := TGCanvas.Create;
    614627  Canvas.Bitmap := Self;
     
    617630destructor TGBitmap.Destroy;
    618631begin
     632  FBackgroundColor.Free;
     633  Canvas.Free;
    619634  Size := Point(0, 0);
    620635  FData.Free;
  • trunk/UMemory.pas

    r13 r15  
    8989    procedure SetItem(Index: Integer; AValue: Byte); override;
    9090  public
     91    constructor Create;
     92    destructor Destroy; override;
    9193    function GetInteger: Integer; override;
    9294    procedure SetInteger(Value: Integer); override;
     
    203205end;
    204206
     207constructor TBitMemory.Create;
     208begin
     209  FData := nil;
     210end;
     211
     212destructor TBitMemory.Destroy;
     213begin
     214  FreeMem(FData);
     215  inherited Destroy;
     216end;
     217
    205218{ TBitBlock }
    206219
Note: See TracChangeset for help on using the changeset viewer.