Autor Beitrag
Wommel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 18



BeitragVerfasst: Di 26.07.05 12:43 
hello


Mal ein Beispiel

ich habe ein Programm bestehend aus Form1 und Form2

Form1 belegt im Windows speicher 7456 kb nun öffne ich Form2 diese beinhaltet nen TImage.. welche ich zu Laufzeit mit einem Bild fülle!

der Speicherverbrauch steigt dadurch auf weit über 9000 kb - schliesse ich nun die Form2 wieder, bleibt der Speicherverbrauch - dennoch - bei den 9 MB - ich möchte aber nun den verbrauchten speicher wieder auf die 7MB bekommen!

Was muss ich dazu machen!?


Ich habe schon vor dem close der Form2 dem TImage NIL zugewiesen....


Danke Euch
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: Di 26.07.05 12:50 
Es kann sein, dass du da gar nichts machen kannst. Wenn du das Image tatsächlich wieder freigibst, dann ist der Speicher frei. Windows reserviert für dein Programm dann aber trotzdem weiterhin soviel Speicher, weil deine Anwendung durchaus soviel verlangen kann - hat sie ja gerade gezeigt.
Das aufwendige Aufteilen der Ressourcen auf die einzelnen Anwendungen wird dadurch nicht so häufig notwendig. Wenn deine Anwendung später mehr Speicher braucht, dann werden zunächst die knappen 2MB von dem Image benutzt, bevor Windows wieder mehr arbeiten muss...

Ganz sicher bin ich dabei aber nicht.

_________________
We are, we were and will not be.
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Di 26.07.05 21:59 
Nicht Windows ist der Schuldige, sondern der Speichermanager von Delphi, welcher den Reservierten Speicher nicht unbedingt zurückgibt.
hallo
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 450

WIN XP, SuSE 9.3
D3 Prof, D6 Pers, 2005 Pers
BeitragVerfasst: Mi 27.07.05 14:48 
Probiers mal mit Image.free oder image.destroy

_________________
Der beste je Programmierte Trojaner: Windows XP
Wäre es nicht adequat, den Usus heterogener Termini zu minimieren?
der_zaehe
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 317

WinXP SP2
D6 Pers, D2005 Prof, VS2005
BeitragVerfasst: Mi 27.07.05 14:56 
user profile iconhallo hat folgendes geschrieben:
Probiers mal mit Image.free oder image.destroy

gibt es eigentlich irgendeinen unterschied zwischen "free" und "destroy" ?

_________________
[inspirationslos]
noidic
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 851

Win 2000 Win XP Vista
D7 Ent, SharpDevelop 2.2
BeitragVerfasst: Mi 27.07.05 15:08 
Wenn ich mich nicht irre, prüft free, ob das Objekt noch da ist. Destroy tut das nicht und knallt, wenn das Objekt bereits freigegeben wurde.
Brueggendiek
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 304

Win 98, Win98SE, Win XP Home
D5 Std
BeitragVerfasst: Mi 27.07.05 21:25 
Hallo!

user profile iconnoidic hat folgendes geschrieben:
Wenn ich mich nicht irre, prüft free, ob das Objekt noch da ist. Destroy tut das nicht und knallt, wenn das Objekt bereits freigegeben wurde.


Falsch!

Das Free prüft, ob der Zeiger Nil ist und gibt das Objekt nur bei gültigem Zeiger frei. Allerdings setzt Free den Zeiger nicht auf Nil - zweimal Free knallt also auch!

Einfache Regel: Beim Aufrufen immer Free (niemals Destroy), beim Überschreiben immer Destroy, niemals Free!

Wenn eine lokle Variable am Beginn einer Prozedur belegt und am Ende freigegeben wird, reicht Free. Wenn die Variable noch benutzt werden könnte, immer FreeAndNil benutzen.

Gruß

Dietmar Brüggendiek
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: Mi 27.07.05 21:45 
Auch wieder falsch: Free prüft gar nix, sondern kapselt einfach nen Aufruf des Destructors. Sonst nix.

Ein TObject(nil).Free; Knall besonders schön, wenn garniert mit schlechtem Code :mrgreen:

Wenn man schon FreeAndNil nutzt (empfehlenswert!), sollte man If Assigned(Var) Then FreeAndNil(Var); aufrufen oder FreeAndNilSecure aus der OIncProcs.pas von Projekt Omorphia nutzen (die ist für Schreibfaule und macht das gleiche).

_________________
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.
maxk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1696
Erhaltene Danke: 1

Win XP, Debian Lenny
Delphi 6 Personal
BeitragVerfasst: Mi 27.07.05 21:46 
user profile iconBrueggendiek hat folgendes geschrieben:
Einfache Regel: Beim Aufrufen immer Free (niemals Destroy), beim Überschreiben immer Destroy, niemals Free!
Das versteh ich nicht, was meinst du mit Überschreiben (override?)?

_________________
Ein Computer wird das tun, was Du programmierst - nicht das, was Du willst.
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: Mi 27.07.05 21:52 
Jup. Genau.

Wenn Du ein Objekt freigibst immer Obj.Free;, wenn Du einen Destructor ableitest immer
ausblenden Delphi-Quelltext
1:
2:
3:
4:
TNewObj = class(TSomething)
public
    desctructor Destroy; override;
end;

_________________
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.
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Mi 27.07.05 21:55 
user profile iconBenBE hat folgendes geschrieben:
Auch wieder falsch: Free prüft gar nix, sondern kapselt einfach nen Aufruf des Destructors. Sonst nix.
So steht's in meiner system.pas:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
procedure TObject.Free;
begin
  if Self <> nil then
    Destroy;
end;


Und ein TObject(nil).Free; wird bei mir fehlerfrei ausgeführt.

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
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: Mi 27.07.05 22:27 
:oops: k, stimmt. Macht D7 genauso ... Muss ich wohl mit CleanUpInstance verwechselt haben. Passiert im Gefecht ;-)

_________________
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.