Вниз
Скачать: CL | DM;

Утечка памяти   Найти похожие ветки 

← →
Lexa   (2003-01-31 12:54) [0]

Скажите образуется ли утечка памяти,если я не уничтожаю объект а просто присваиваю ему предка.

type
TMyButton=class(TButton)
............
end;
TsecondButton=class(TMyButton)
...........
end;
......
var
Button:TMyButton;
begin
Button := TMyButton.Create(Form1);
Button := TSecondButton.Create(Form1);
end.


← →
han_malign ©   (2003-01-31 12:58) [1]

Естественно - для классов референсы автоматически не прокатывают - только для открытых строк, динамических массивов и COM интерфейсов


← →
REA ©   (2003-01-31 13:11) [2]

В данном случае нет, поскольку владельцем кнопки становится форма и она ее уничтожит, но ссылку ты теряешь.


← →
Calm ©   (2003-01-31 13:20) [3]


> В данном случае нет,

Это как это "нет" ???

han_malign © (31.01.03 12:58) прав!


← →
Palladin ©   (2003-01-31 13:24) [4]

2 Calm

так это нет
объект зарегестрирован во владельце... и тот его удалит в свое время... просто достучатся к нему уже неоткуда..


← →
REA ©   (2003-01-31 13:25) [5]

Классы наследники TButton, который наследник TComponent, делает следующее:

constructor TComponent.Create(AOwner: TComponent);
begin
FComponentStyle := [csInheritable];
if AOwner <> nil then AOwner.InsertComponent(Self);
end;

destructor TComponent.Destroy;
begin
Destroying;
if FFreeNotifies <> nil then
begin
while Assigned(FFreeNotifies) and (FFreeNotifies.Count > 0) do
TComponent(FFreeNotifies[FFreeNotifies.Count - 1]).Notification(Self, opRemove);
FreeAndNil(FFreeNotifies);
end;
DestroyComponents;
if FOwner <> nil then FOwner.RemoveComponent(Self);
inherited Destroy;
end;

procedure TComponent.DestroyComponents;
var
Instance: TComponent;
begin
while FComponents <> nil do
begin
Instance := FComponents.Last;
if (csFreeNotification in Instance.FComponentState)
or (FComponentState * [csDesigning, csInline] = [csDesigning, csInline]) then
RemoveComponent(Instance)
else
Remove(Instance);
Instance.Destroy; end;
end;



Страницы: 1 вся ветка

Скачать: CL | DM;



Память: 0.46 MB
Время: 0.012 c
4-29150
malkolinge
2002-12-26 12:29
2003.02.10
TreeView with CheckBox


14-29026
Navigor
2003-01-23 16:02
2003.02.10
Как String to Integer Сделать


1-28826
peugeot605
2003-02-02 18:13
2003.02.10
Динамическое создание объектов


1-28802
John
2003-02-02 10:44
2003.02.10
Работа с файлами...


14-29040
Zhenka
2003-01-24 14:06
2003.02.10
Masters, А какие параметры у Ф-ии ShAddToRescentDocs




   Наверх