Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2003.02.10;
Скачать: 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 вся ветка

Текущий архив: 2003.02.10;
Скачать: CL | DM;

Наверх




Память: 0.48 MB
Время: 0.019 c
1-28784
John
2003-02-01 19:58
2003.02.10
HELP!!! Работа с файлами и памятью...


4-29177
BigDAN
2002-12-25 14:35
2003.02.10
Взведена ли критическая секция???


4-29162
max001
2002-12-26 20:18
2003.02.10
люди очень нужна помощь!!!!!!!!!!!!


3-28588
AndrewVolkov
2003-01-23 18:14
2003.02.10
MS SQL 2000 + MSSQL 2000


1-28788
Son!K
2003-02-01 22:28
2003.02.10
Группы