Autor Beitrag
mcst09
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 112



BeitragVerfasst: So 07.05.06 16:30 
Hallo,

folgende Fragen:

1. Was genaus sind Speicherleaks??
Ich verstehe unter SpeicherLeaks zum Beispiel, wenn ich eine Variable vom Typ TStringList erzeuge und sie am Ende der Funktion nicht mehr freigebe (if assigned(variable) then FreeAndNil(variable);). Sehe ich das so richtig?? Was gibts noch für SpeicherLeaks???

2. Wie vermeide ich SpeicherLeaks??
Sehe ich das richtig wenn ich behaupte, dass ich innerhalb einer Funktion alle Variablen die .Create wurden, im Finally wieder auf "if assigned(variable) then FreeAndNil(variable);" setzen muss?
Was kann man noch tun um SpeicherLeaks zu verhindern??

Danke
Axl


Moderiert von user profile iconGausi: Topic aus Algorithmen, Optimierung und Assembler verschoben am So 07.05.2006 um 17:52
Spaceguide
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 552


(D3/D7/D8) Prof.
BeitragVerfasst: So 07.05.06 16:41 
Ich empfehle die Verwendung von FastMM4. Dieser zeigt dir bei Programmende alle Variablen an, die nicht mehr freigegeben wurden.
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: So 07.05.06 16:46 
Ähm genaugenommen reichts zu schreiben aTStringList.Free; (das überprüft auch, ob die variable schon freigegeben wurde, iirc.. wenn nich, dann mach halt if x<>nil then x.free; )
Andererseits gibt Delphi iirc z.B. Lokale Variablen automatisch frei am ende der Procedure. Aber dazu musst du Fachmänner wie BenBE( :flehan: ) & co. fragen ^^

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: So 07.05.06 16:51 
user profile iconJayEff hat folgendes geschrieben:
Andererseits gibt Delphi iirc z.B. Lokale Variablen automatisch frei am ende der Procedure.
Ich bin zwar kein Fachmann (:mrgreen:), aber das stimmt nicht. Normale Variablen wie integer etc. muss man nicht selbst explizit freigeben, aber wenn du in einer Prozedur etwas mit create erstellst, dann bist du selbst dafür verantwortlich, dass es mit free wieder wegkommt.

_________________
We are, we were and will not be.
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: So 07.05.06 16:57 
Na siehste! das hab ich doch genau gemeint und auch so geschrieben! (*schnell auf edit klickts* :oops: )
Ja klar, da is mir spontan nen Denkfehler unterlaufen ... ^^ Klar dass damit mehr die "normalen" variablen gemeint waren >.>

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.