
17.08.2013, 15:22
|
Прохожий
|
|
Регистрация: 20.08.2011
Сообщения: 2
Версия Delphi: RAD 2010
Репутация: 10
|
|
Не уничтожается класс - происходит утечка памяти
Ребята создал класс который отрисовывает кубики рандомного цвета и закинул его Creat и destroy на таймер. Кубики отрисовываются как задумывалось но вот вот сам класс не уничтожается и происходит утечка памяти, проверял по диспетчеру задач,через пять отрисовок память увеличивается на 5kb. Прилагаю код ниже , подозреваю что не корректно уничтожаю объект.
Код:
unit Brick;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
img_Fon: TImage;
tmr_1: TTimer;
procedure tmr_1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
TBrick = class
constructor Create (New_X_Y:TPoint;New_Fon:TCanvas;NewX_W,NewY_H:Integer;_Brush:TBrushStyle;color:Integer);
function Color_Brick (_color_Brick_ : array of Integer):Integer; // рандомит цвет кубика
// New_X_Y:TPoint - верхний левый угол кубика
// New_Fon:TCanvas - передаю параметр на каком объекте отрисовывать
// NewX_W,NewY_H - ширина и высота кубика
// _Brush:TBrushStyle;color:Integer - соответственно стиль и цвет заполнения кубика
end;
var
Form1: TForm1;
const
//массив цветов кубиков
_Color_Brick : array [1..12] of Integer = (clAqua, clBlue, clFuchsia, clGreen,
clLime, clMaroon, clNavy, clOlive, clPurple, clRed, clTeal, clYellow);
implementation
{$R *.dfm}
{ TBrick }
function TBrick.Color_Brick(_color_Brick_ :array of Integer): Integer;
begin
Randomize;
Result := _Color_Brick[Random(12)+1];
end;
constructor TBrick.Create(New_X_Y: TPoint; New_Fon: TCanvas;NewX_W,NewY_H:Integer;_Brush:TBrushStyle;color:Integer);
begin
New_Fon.Brush.Style := _Brush;
New_Fon.Brush.Color := color;
New_Fon.FillRect(Bounds(New_X_Y.X ,New_X_Y.Y, NewX_W, NewY_H));
end;
procedure TForm1.tmr_1Timer(Sender: TObject);
var
Brick : TBrick;
I,j,c: Integer;
x,y:Integer;
begin
y := 10 ;
x := 10 ;
Randomize;
for i := 1 to 12 do
begin
c := Random(12)+1;
for j := 0 to 10 do
begin
Brick := TBrick.Create(Point(x,y),img_Fon.Canvas,53,25,bsSolid,_color_Brick[c]);
Brick.Destroy;
x := x + 53 + 3;
end;
x := 10;
y := y + 25 + 3;
end;
end;
end.
В чем проблема подскажите пожалуста.
|