Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   OOP (https://www.clubdelphi.com/foros/forumdisplay.php?f=5)
-   -   Sobre las perdidas de memoria (memory leak) (https://www.clubdelphi.com/foros/showthread.php?t=42176)

sitrico 05-04-2007 18:15:40

Sobre las perdidas de memoria (memory leak)
 
Estoy trabajando en una aplicación y me ví en la necesidad de crear un objeto (practicamente un componente), y tengo que insertarle varios controles en tiempo de ejecución. Los creo con el siguiente codigo:

Código Delphi [-]
constructor TSNMCTimePlanner.Create(AOwner: TComponent);
begin
  inherited;
FHoursFont := TFont.Create;
FTimePanel := TPanel.Create(Self);
end;

destructor TSNMCTimePlanner.Destroy;
begin
FTimePanel.Free;
FHoursFont.Free;
inherited Destroy;
end;

procedure TSNMCTimePlanner.ShowHours;
Var
i,h : integer;
l : tLabel;
begin
   h := HourOf(FStartTime);
For i := 0 to HoursBetween(FEndTime,FStartTime) do
   Begin
   l := TLabel.Create(FTimePanel);
   l.Left := 5;
   l.Top := (i * FTimeBlockSize * TimeBlockPerHour);
   l.Font := FHoursFont;
   l.Caption := IntToStr(h);
   l.AutoSize := False;
   l.Width := 25;
   l.Alignment := taCenter; 
   FTimePanel.InsertControl(l);
   Inc(h);
   If h = 13 Then h := 1;
   End;
end;

end.

Con FTimePanel y FHoursFont no creo que haya problema, pero con los componentes insertados (en ShowHours) no estoy seguro si se liberaran correctamente al destuir el objeto.

Alguien me sabria decir si los tLabel creados con el ciclo for se liberarán correctamente. Segun tengo entendido al crearlos con el owner asignado al fTimePanel al destruir fTimePanel se destuirán todos los componentes que le pertenezcan

Uso D7, gracias

Lepe 05-04-2007 18:56:25

No tendrás problemas. Un contenedor (el panel) al ser destruido, liberará todos los controles que contiene.

saludos

roman 05-04-2007 19:30:54

De cualquier forma, siempre es bueno usar herramientas como MemProof, que te indicarán cualquier memoria asignada que no se destruya.

// Saludos


La franja horaria es GMT +2. Ahora son las 16:31:57.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi