Autor Beitrag
Anfänger
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 128

WinXP
D3 Prof
BeitragVerfasst: So 24.10.04 18:51 
Wann ist es eigendlich notwendig den Befehl Free anzuwenden?
Mir ist aufgefallen, dass der Befehl bei exceptions immer angewendet wird, aber sollte man ihn auch nutzen, wenn die Procedur ganz normal abgeschlossen wurde und das Objekt nichtmehr benötigt wird?

Warum benötigt z.B. ein Bitmap Creat und Free und Integer nicht?
tommie-lie
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 4373

Ubuntu 7.10 "Gutsy Gibbon"

BeitragVerfasst: So 24.10.04 19:00 
Alle Objektinstanzen (Integer sind keine, sondern gehören zu den Grunddatentypen) rufen über Free ihren Destructor auf, der den Speicher, den das Objekt belegt, wieder freigibt. Der sollte nicht nur bei Exceptions aufgerufen werden, sondern immer, wenn das Objekt nicht mehr benötigt wird. Bei Exceptions wandert der Free-Aufruf nur in das finally, damit er auf jeden Fall ausgeführt wird, selbst wenn eine Exception normalerweise die Codeausführung abbrechen würde.

_________________
Your computer is designed to become slower and more unreliable over time, so you have to upgrade. But if you'd like some false hope, I can tell you how to defragment your disk. - Dilbert
Anfänger Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 128

WinXP
D3 Prof
BeitragVerfasst: So 24.10.04 19:44 
Danke, aber wenn ich eine Variable in einer Prozedur anmelde, wird sie bei nach der beendung der Prozedur nicht automatisch aus dem Arbeitspeicher genommen?

Was ist dann mit den Objekten auf der Form? Dann müsste man ja jedes Objekt in OnClose frei geben?
Elite
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: So 24.10.04 19:53 
Stichwort Komponentenhierarchie.
Du musst jedes Objekt freigeben, für das du keinen Parent gesetzt hast. Darunter fallen also alle selbst erzeugten(ok, fast alle),aber keine Variablen, sondern nur Instanzen einer Klasse ... also kein Integer, kein String, kein bool, kein Button, Label, Edit auf deiner Form, sondern nur die von dir manuell erzeugten, denen du kein Parent zuweist.
tommie-lie
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 4373

Ubuntu 7.10 "Gutsy Gibbon"

BeitragVerfasst: So 24.10.04 19:57 
Elite hat folgendes geschrieben:
keine Variablen
Objekte werden auch in Variablen gespeichert :tongue:

_________________
Your computer is designed to become slower and more unreliable over time, so you have to upgrade. But if you'd like some false hope, I can tell you how to defragment your disk. - Dilbert


Zuletzt bearbeitet von tommie-lie am So 24.10.04 20:15, insgesamt 1-mal bearbeitet
Luzzifus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 200

Win2K
D6 Prof
BeitragVerfasst: So 24.10.04 20:10 
tommie-lie hat folgendes geschrieben:
Elite hat folgendes geschrieben:
keine Variablen
Objekte werden auch in Variablen gespcihert :tongue:

das sind dann aber Objekt-Instanzen und nicht das was der normale user unter ner variable versteht (auch wenn's prinzipiell stimmt).
Anfänger Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 128

WinXP
D3 Prof
BeitragVerfasst: Di 26.10.04 21:59 
Was währe, wenn ich z.B. einen Button zur Laufzeit erstelle?
Macht das hierbei einen unterschied?
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: Di 26.10.04 22:16 
Nein. Wenn du ein Objekt instantiierst legst du dieses auch, z.B. inn der Application, dem Form oder ähnlichen Konstrukten ab. Das sind Speichertechnisch auch nur Variablen.

_________________
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.
Anfänger Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 128

WinXP
D3 Prof
BeitragVerfasst: Do 28.10.04 20:59 
Ok, habs kapiert :lol:
Danke für die Hilfe.