Ver Mensaje Individual
  #1  
Antiguo 05-04-2007
Avatar de sitrico
[sitrico] sitrico is offline
Miembro Premium
 
Registrado: may 2003
Ubicación: Caracas, Venezuela
Posts: 295
Reputación: 22
sitrico Va por buen camino
Question 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
__________________
Sitrico
Responder Con Cita