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: Mo 12.03.07 01:40 
Hallo Leute ich habe folgende Funktion, welche in meinem Programm von einem Timer ausgelöst immer wieder aufgerufen wird. Jedoch frisst diese Funktion, wie tests bestätigt haben, den Arbeitsspeicher laut Taskmanager. Nach einiger Zeit bekomme ich nen Fehler vom System, dass die Anwendung keine freien Systemrescourcen mehr finden kann und schmiert ab. Wenn ich diese Funktion auskommentiere, dann steigt der Speicherverbrauch laut Taskmanager nicht mehr so stark an. Wo sind da bitte noch Speicherlücken? Ich gebe doch die 2 benutzen Objekte wieder frei?!

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:
function TMainForm.GetTrayIcon(idx: Integer): TIcon;
var
  Bitmap: TBitmap;
  ImageList: TImageList;
  ctemp: string;
begin
  Bitmap := TBitmap.Create;
  Bitmap.SetSize(16, 16);
  Bitmap.Canvas.Pen.Color := clBlue;

  ctemp := IntToStr(NORMALERWEISE_ZWEI_STELLIGER_INT);
  case Length(ctemp) of
  1: begin
    Bitmap.Canvas.TextOut(1, 2, ' ');
    Bitmap.Canvas.TextOut(7, 2, ctemp[1]);
  end;
  2: begin
    Bitmap.Canvas.TextOut(1, 2, ctemp[1]);
    Bitmap.Canvas.TextOut(7, 2, ctemp[2]);
  end;
  else begin
    Bitmap.Canvas.TextOut(1, 2, '-');
    Bitmap.Canvas.TextOut(7, 2, '-');
  end;
  end;

  result := TIcon.Create;
  ImageList := TImageList.Create(nil);
  ImageList.AddMasked(Bitmap, clWhite);
  ImageList.GetIcon(0, result);
  ImageList.Clear;
  ImageList.Free;
  Bitmap.Free;
end;


Mfg Meolus

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

Windows 7
Delphi7 - Delphi XE
BeitragVerfasst: Mo 12.03.07 02:32 
Gibst du das TIcon auch irgendwo wieder frei?

_________________
"Ich bin bekannt für meine Ironie. Aber auf den Gedanken, im Hafen von New York eine Freiheitsstatue zu errichten, wäre selbst ich nicht gekommen." - George Bernhard Shaw
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: Mo 12.03.07 11:57 
Ich benutze diese TrayIcon-Komponenten: www.swissdelphicente...showcode.php?id=1303

Ich weise es einfach der Eigenschaft zu:
ausblenden Delphi-Quelltext
1:
TrayIcon.Icon := GetTrayIcon(i);					


Ich hab zwar auch schonmal nen "TrayIcon.Icon.Free;" davor gesetzt, daber dann hat der auf einmal immer nur noch das Application.Icon im Systray angezeigt.

---

Habs grad nochmal versucht, und jetzt geht das mit dem Icon.Free :-/
Hat sich also erledigt, wenn da jetzt nicht irgendwo wirklichen nen Bug in der Komponenten ist, dem ich da immer auf den Leim gehe.

_________________
Real programmers don't comment their code;
if it was hard to write, it should be hard to read.
wulfskin
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1349
Erhaltene Danke: 1

Win XP
D5 Pers (SSL), D2005 Pro, C, C#
BeitragVerfasst: Mo 12.03.07 12:03 
Hallo,

versuchs mal so:
ausblenden Delphi-Quelltext
1:
2:
3:
  Icon := GetTrayIcon(bla);
  TrayIcon.Icon.Assign(Icon);
  Icon.Free;
Gruß Hape!
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: Mo 12.03.07 13:55 
Das "TrayIcon.Icon.Assign(Icon);" mag er nicht. Die TrayIcon-Klasse hat aber ja auch selber eine Setter-Methode für das Icon:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
if fIcon <> Icon then
  begin
    fIcon.Assign(Icon);
    fData.hIcon := Icon.Handle;
    Changed;
  end;


ausblenden Delphi-Quelltext
1:
2:
3:
  Icon := GetTrayIcon(bla);
  TrayIcon.Icon := Icon;
  Icon.Free;

scheint das Problem nun gelöst zu haben, thx.


Zudem hab ich jetzt eine Vorabüberprüfung, ob sich überhaupt der Wert der auf das Icon gepinselt werden soll geändert hat. So zögere ich es dann zur Not noch weiter raus :D

_________________
Real programmers don't comment their code;
if it was hard to write, it should be hard to read.