Autor Beitrag
meolus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 78

Gentoo, Debian, Win7 64-bit, WinXP
Delphi 2006 Prof., Delphi 2005 PE
BeitragVerfasst: Do 25.08.05 17:09 
Worin besteht genau der Unterschied der Methoden "Free" und "Destroy" bei Objekten?


Moderiert von user profile iconChristian S.: Topic aus VCL (Visual Component Library) verschoben am Do 25.08.2005 um 20:51

_________________
Real programmers don't comment their code;
if it was hard to write, it should be hard to read.
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Do 25.08.05 17:22 
Free ruft Destrox auf, überprüft aber vorher, ob das Objekt nicht nill ist, deswegen nie Destroy direkt aufrufen.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Do 25.08.05 19:04 
Ein weiterer wichtiger Unterschied ist, dass Destroy als destructor implementiert ist, während Free eine simple Methode ist. Das bewirkt auf unterster Ebene, dass Destroy einen weiteren Parameter (versteckt) übergeben bekommt, der angibt, ob der Speicher freigegeben werden soll, oder, ob dies (durch weitere Destructor-Aufrufe) bereits iniziiert wurde.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
meolus Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 78

Gentoo, Debian, Win7 64-bit, WinXP
Delphi 2006 Prof., Delphi 2005 PE
BeitragVerfasst: Do 25.08.05 19:12 
Also in jedemfall "Free" zum entfernen des Objekts verwenden wie Luckie sagte, ja?

BenBE, meinst du jetzt, dass das mit der Speicherfreigabe im "Destroy" drin ist oder das "Free" "Destroy mit Speicherfreigabe" aufruft? Was müsste denn im Destructor stehen, damit der Speicherfreiggeben wird?

_________________
Real programmers don't comment their code;
if it was hard to write, it should be hard to read.
blaueled
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 133

Win XP
D5
BeitragVerfasst: Do 25.08.05 19:15 
Free
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Do 25.08.05 19:50 
Aufrufen sollte man IMMER Free.

Das was ich noch erklärt hab, sind einige Interna, wie das mit der Direktive "destructor" funktioniert. Um das aber vollständig zu erklären müsste ich VCL-Sources posten, was aber nicht erlaubt ist. Außerdem erfordert das Verständnis dieser Sourcen ASM-Kenntnisse und etwas Wissen über den MM von Delphi.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.