Autor Beitrag
FriFra
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 557

Win XP Prof, Win XP Home,Win Server 2003,Win 98SE,Win 2000,Win NT4,Win 3.11,Suse Linux 7.3 Prof,Suse Linux 8.0 Prof
D2k5 Prof, D7 Prof, D5 Standard, D3 Prof, K3 Prof
BeitragVerfasst: Mi 04.02.04 11:07 
Langsam aber sicher schaufelt mein Programm den Speicher zu.
Vielleicht sieht ja jemand von euch den Fehler:
Source:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
var 
TNA_Icon: TIcon; //Icon für den TNA 
G_IP: string; //globale Variable für die IP 

... 

procedure TForm1.SetIcon(Loading, Ignoring, Stopped, Plugin:
  boolean);
var
  RS: TResourceStream;
  sI: string;
  oldicon: longint;
begin
  if IsClosing = False then
  begin
    IconReady := False;
    RS := nil;
    try
      if G_IP = '0.0.0.0'#0 then
        sI := 'IN'
      else if G_IP = '0.0.0.0' then
        sI := 'OF'
      else
        sI := 'ON';

      { Ladeanzeige }
      if Loading then
        sI := sI + '_LO';

      { Ignorieren/Stopped }
      if Ignoring then
        sI := sI + '_IG'
      else if Stopped then
        sI := sI + '_ST';

      { Plugin }
      if Plugin then
        sI := sI + '_PL';

      { Farbtiefe }
      sI := sI + GetIconSufix;

      { TNA-Icon }
      try
        RS := TResourceStream.Create(0, sI, RT_RCDATA);
        RS.Position := 0;
        oldIcon := TNA_Icon.ReleaseHandle;
        if oldIcon <> 0 then
          DestroyIcon(TNA_Icon.Handle);
        TNA_Icon.LoadFromStream(RS);
        //DestroyIcon(IconData.hIcon);
        IconData.hIcon := TNA_Icon.Handle;
      finally
        RS.Free;
      end;

      { Statusanzeige }
      try
        RS := TResourceStream.Create(0, sI, RT_RCDATA);
        RS.Position := 0;

        oldIcon := Image1.Picture.Icon.ReleaseHandle;
        if oldIcon <> 0 then
          DestroyIcon(Image1.Picture.Icon.Handle);
        Image1.Picture.Icon.LoadFromStream(RS);
        Image1.Repaint;
        Edit3.Text := G_IP;
        Label7.Caption := G_IT;

        if G_IP = '0.0.0.0'#0 then
        begin
          ToolButton11.Enabled := False;
          Label2.Caption := 'undefined';
        end
        else if G_IP = '0.0.0.0' then
        begin
          ToolButton11.Enabled := False;
          Label2.Caption := 'Offline';
        end
        else
        begin
          ToolButton11.Enabled := True;
          Label2.Caption := 'Online';
        end;
      finally
        RS.Free;
      end;
      {//Image1.Picture.Icon.ReleaseHandle;
      DestroyIcon(Image1.Picture.Icon.Handle);
      Image1.Picture.Icon.Assign(TNA_Icon);}


      { TNA-Text }
      StrPLCopy(IconData.szTip, '[' + Label2.Caption + ']' + TNAbr + 'WAN-IP: '
        + Edit3.Text + TNAbr + 'LAN-IP: ' + Edit4.Text, 63);

      if IsMinimized = True then
        Shell_NotifyIcon(NIM_MODIFY, @IconData);
    finally
      IconReady := True;
    end;
  end;
end;


:idea: Ich habe den Fehler schon eingegrenzt, indem ich das eine oder andere auskommentiert habe. Wenn ich die Zuweisung der Icons auskommentiere bleibt der Speicher frei...

Ich weiss also, dass es an Zuweisung der Icons, bzw. der nicht korrekten Freigabe liegt, aber ich weiss nicht genau warum. :roll:

_________________
Michael
(principal certified lotus professional - developer)


Zuletzt bearbeitet von FriFra am Mi 04.02.04 13:05, insgesamt 1-mal bearbeitet
MaxiTB
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 679

Win2000, WinXp, Workbench ;-)
D7 Ent, VS2003 Arch.
BeitragVerfasst: Mi 04.02.04 12:32 
ausblenden Delphi-Quelltext
1:
Image1.Picture.Icon.ReleaseHandle					


Da haben wir ja schon den Bug - du checkst nicht den Rückgabewert.

Übrigends ... das Thema wurde ja eh schon von dir angeschnitten und wurde aufgeklärt:
www.delphi-forum.de/...t=21182&start=19

_________________
Euer Mäxchen
Wer früher stirbt, ist länger tot.
FriFra Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 557

Win XP Prof, Win XP Home,Win Server 2003,Win 98SE,Win 2000,Win NT4,Win 3.11,Suse Linux 7.3 Prof,Suse Linux 8.0 Prof
D2k5 Prof, D7 Prof, D5 Standard, D3 Prof, K3 Prof
BeitragVerfasst: Mi 04.02.04 12:46 
Es wurde nicht aufgeklärt, da das Problem nach wie vor besteht. Wo bitte ist im angegebenen Thread eine passende Lösung? Ich habe alle Lösungsvorschläge getestet, aber früher oder später schaufelt sich der Speicher trotzdem zu!

Ausserdem habe ich den Code massiv verändert. Icons werden nicht mehr kombiniert sondern alle Kombinationen liegen fertig in der Resource, was eine deutliche Verbesserung brachte, aber eben keine Lösung.

_________________
Michael
(principal certified lotus professional - developer)
MaxiTB
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 679

Win2000, WinXp, Workbench ;-)
D7 Ent, VS2003 Arch.
BeitragVerfasst: Mi 04.02.04 12:58 
Zitat:
You get the problem when you have two TIcons that share the same
TIconImage. Suppose you want to change one of the icon's handles, you
say:

ausblenden Delphi-Quelltext
1:
2:
3:
oldIcon := icon1.ReleaseHandle; 
if oldIcon <> 0 then DestroyIcon (oldIcon); 
icon1.Handle := newIcon;


Da stehts doch. Und der Bug ist immer noch drinnen ... siehe deinen Code oben.

_________________
Euer Mäxchen
Wer früher stirbt, ist länger tot.
FriFra Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 557

Win XP Prof, Win XP Home,Win Server 2003,Win 98SE,Win 2000,Win NT4,Win 3.11,Suse Linux 7.3 Prof,Suse Linux 8.0 Prof
D2k5 Prof, D7 Prof, D5 Standard, D3 Prof, K3 Prof
BeitragVerfasst: Mi 04.02.04 13:10 
Ich hab den Code jetzt nochmal verändert (das hatte ich auch schonmal drin)... aber das Problem besteht nach wie vor. Und es hängt definitiv mit der Zuweisung der Icons zusammen... wenn ich die Zuweisungen auskommentiere "frisst" das Programm keinen Speicher mehr.

Interessant an der Sache finde ich aber, dass wenn ich mein Programm anzeige (TNA-Icon ausgeblendet) und anschliessend wieder minimiere (TNA-Icon eingeblendet) der Speicherverbrauch massiv zurückgeht (z.B. 13MB -> 2MB) :roll: ...

_________________
Michael
(principal certified lotus professional - developer)
MaxiTB
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 679

Win2000, WinXp, Workbench ;-)
D7 Ent, VS2003 Arch.
BeitragVerfasst: Mi 04.02.04 13:22 
Hm, naja, also die eine Sache ist mal sicher ein Bug.

Hab ja damals deswegen jede Menge VCL Sourcecode durchforstet, nur um dann von toms ein paar Sekunden später zu erfahren, daß es eh ein dokumentierter Bug ist :? .

Aber ansonsten war an dieser Stelle eigentlich nix mehr zu finden ... selbst die combine war ja sauber, d.h. es muß an anderer Stelle eventuell die Icons nicht freigegeben werden ... ist mal so mein Gedanke auf die schnelle ...

_________________
Euer Mäxchen
Wer früher stirbt, ist länger tot.
FriFra Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 557

Win XP Prof, Win XP Home,Win Server 2003,Win 98SE,Win 2000,Win NT4,Win 3.11,Suse Linux 7.3 Prof,Suse Linux 8.0 Prof
D2k5 Prof, D7 Prof, D5 Standard, D3 Prof, K3 Prof
BeitragVerfasst: Mi 04.02.04 13:30 
Wie geasgt, mit auskommentierter Zuweisung gibt es keine Probleme. Allerdings wird das System erst nach einigen Tausend zuweisungen instabiel...
Es fängt dann z.B. so an:
user defined image
(Taskmanager ohne Fenstertitel etc.)
Später kann man dann fast nichts mehr machen und div. Fenster zeichnen ihre Controls wild über den Desktop.

_________________
Michael
(principal certified lotus professional - developer)
MaxiTB
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 679

Win2000, WinXp, Workbench ;-)
D7 Ent, VS2003 Arch.
BeitragVerfasst: Mi 04.02.04 13:33 
Ähm ... blöde frage, aber wo wird eigentlich das TNA_ICON freigegeben ?
Durch das Assign wird ja wieder eine Kopie erstellt ... :roll:

/EDIT: Sorry - habs schon gesehen. Das wird schon vorher freigegeben ...
Aber irgendwo muß was überbleiben ...

_________________
Euer Mäxchen
Wer früher stirbt, ist länger tot.