Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Hilfestellung zu meinem Speicherleck (https://www.delphipraxis.net/160359-hilfestellung-zu-meinem-speicherleck.html)

delphinub23 9. Mai 2011 18:00

Delphi-Version: 2010

Hilfestellung zu meinem Speicherleck
 
Hallo Community,

in meinem Projekt arbeitet ich mit einem array aus TStringLists, welche ihren Inhalt aus verschiedenen Funktionen - Timer 3 sek Intervall - zugewiesen bekommen. Leider frisst meine Applikation bei jedem OnTimer-Ereignis 0.0XXK Speicher. Steigend.

Ich habe versucht, dem MemoryLeak mit FastMM4 auf die Schliche zu kommen, aber daraus werd ich nicht schlau.

Knnte mir jemand Hilfestellung geben (Log oder auch Source)?

Anbei ein Ausschnitt meines FastMM4Log:


Code:
This block was allocated by thread 0xDAC, and the stack trace (return addresses) at the time was:
4043E2 
404FC3 
40555A
43B706 
406306 
4E4C91 
4EFA87 
4EFA25 
4EFA48 
4F035A
751C6D91 [Unknown function at GetThreadDesktop]

The block is currently used for an object of class: TStringList

The allocation number is: 65080

Current memory dump of 256 bytes starting at pointer address 7EF898A0:
94 F8 42 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 90 FB EB 7E
13 00 00 00 1C 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 6A 9D 1B 1C 80 80 80 80 80 80 80 80 00 00 00 00 E0 4B F8 7E
00 00 00 00 00 00 00 00 D8 E9 40 00 00 00 00 00 08 11 01 00 E2 43 40 00 C3 4F 40 00 5A 55 40 00
06 B7 43 00 09 DB 40 00 5F 4B 4E 00 25 FA 4E 00 7B FB 4E 00 C5 FF 4E 00 04 FF 4E 00 4F 3E 4B 00
AC 0D 00 00 FE 43 40 00 E1 4F 40 00 A5 55 40 00 B5 8D 43 00 27 50 40 00 C5 69 4D 00 CA 77 4D 00
27 50 40 00 8A DA 4E 00 BA FF 4E 00 04 FF 4E 00 AC 0D 00 00 4C 00 00 00 A4 E7 4C 00 AB 62 AF 85
94 F8 42 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 10 FD EB 7E
    B . . . . . . . . . . . . . . . . . . . . . . . . .       ~
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . j   . .                 . . . .   K   ~
. . . . . . . .     @  . . . . . . . . .   C @  .   O @  . Z U @  .
.   C . .   @  . _  K N . %    N . {    N .     N . .   N . O > K .
  . . .   C @  .   O @  .   U @  .     C . ' P @  .   i M .   w M .
' P @  .     N .     N . .   N .   . . . L . . .     L .   b  
    B . . . . . . . . . . . . . . . . . . . . . . . . . .     ~

--------------------------------2011/5/9 18:32:23--------------------------------
A memory block has been leaked. The size is: 84

This block was allocated by thread 0xDAC, and the stack trace (return addresses) at the time was:
4043E2 
404FC3 
40555A
43B706 
40DB09 
4E4B5F
4EFA25 
4EFB7B
4EFFC5 
4EFF04 
4B3E4F

The block is currently used for an object of class: TStringList

The allocation number is: 69896

Current memory dump of 256 bytes starting at pointer address 7EF89980:
94 F8 42 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 10 FD EB 7E
13 00 00 00 1C 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 54 9D 50 7A 80 80 80 80 80 80 80 80 00 00 00 00 E0 4B F8 7E
00 00 00 00 00 00 00 00 D8 E9 40 00 00 00 00 00 DC 15 01 00 E2 43 40 00 C7 74 40 00 04 6C 40 00
00 4C 4E 00 25 FA 4E 00 7B FB 4E 00 C5 FF 4E 00 04 FF 4E 00 4F 3E 4B 00 C9 3F 4B 00 C3 38 4B 00
AC 0D 00 00 FE 43 40 00 DD 62 40 00 1E 6C 40 00 FC 55 4E 00 1E 6C 40 00 0E 4C 4E 00 25 FA 4E 00
7B FB 4E 00 C5 FF 4E 00 04 FF 4E 00 4F 3E 4B 00 AC 0D 00 00 4E 00 00 00 B0 04 02 00 B4 29 8F 85
B0 04 02 00 01 00 00 00 20 00 00 00 46 00 6C 00 61 00 73 00 68 00 55 00 74 00 69 00 6C 00 36 00
    B . . . . . . . . . . . . . . . . . . . . . . . . . .     ~
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . T   P z                 . . . .   K   ~
. . . . . . . .     @  . . . . .   . . .   C @  .   t @  . . l @  .
. L N . %    N . {    N .     N . .   N . O > K .   ?  K .   8  K .
  . . .   C @  .   b @  . . l @  .   U N . . l @  . . L N . %    N .
{    N .     N . .   N . O > K .   . . . N . . .   . . .   )  
  . . . . . . .    . . . F . l . a . s . h . U . t . i . l . 6  .

--------------------------------2011/5/9 18:32:23--------------------------------
A memory block has been leaked. The size is: 84

This block was allocated by thread 0xDAC, and the stack trace (return addresses) at the time was:
4043E2 
4074C7 
406C04 
4E4C00 
4EFA25 
4EFB7B
4EFFC5 
4EFF04 
4B3E4F
4B3FC9 
4B38C3 

The block is currently used for an object of class: UnicodeString

The allocation number is: 71132

Current memory dump of 256 bytes starting at pointer address 7EF89A60:
B0 04 02 00 01 00 00 00 20 00 00 00 46 00 6C 00 61 00 73 00 68 00 55 00 74 00 69 00 6C 00 36 00
34 00 5F 00 31 00 30 00 5F 00 33 00 5F 00 31 00 36 00 32 00 5F 00 41 00 63 00 74 00 69 00 76 00
65 00 58 00 2E 00 65 00 78 00 65 00 00 00 4B D6 70 7A 80 80 80 80 80 80 00 00 00 00 41 9E F8 7E
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 D4 10 01 00 E2 43 40 00 C3 4F 40 00 5A 55 40 00
8B 4B 48 00 CC 4F 40 00 5A 55 40 00 BB 4D 48 00 E8 83 48 00 D6 57 48 00 C5 96 1C 75 3D 58 48 00
AC 0D 00 00 E1 4F 40 00 A5 55 40 00 F2 4B 48 00 27 50 40 00 5F 4E 48 00 27 50 40 00 A3 4E 48 00
11 97 48 00 0E 90 48 00 78 FE 61 72 FA 62 1C 75 AC 0D 00 00 54 00 00 00 78 48 48 00 3C B9 F3 E0
64 12 50 00 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80
  . . . . . . .    . . . F . l . a . s . h . U . t . i . l . 6  .
4  . _  . 1  . 0  . _  . 3  . _  . 1  . 6  . 2  . _  . A . c . t . i . v .
e . X . . . e . x . e . . . K   p z             . . . . A     ~
. . . . . . . . . . . . . . . .   . . .   C @  .   O @  . Z U @  .
  K H .   O @  . Z U @  .   M H .     H .   W H .     . u = X H .
  . . .   O @  .   U @  .   K H . ' P @  . _  N H . ' P @  .   N H .
.   H . .   H . x   a r   b . u   . . . T . . . x H H . <    
d . P .                                                      

--------------------------------2011/5/9 18:32:23--------------------------------
A memory block has been leaked. The size is: 36

This block was allocated by thread 0xDAC, and the stack trace (return addresses) at the time was:
4043E2 
4074C7 
406C04 
4E4C00 
4E4AB4 
405027 
4EF230 
4EF322 
41E266 
4D7837 
4D7473 

The block is currently used for an object of class: UnicodeString

The allocation number is: 5266

Current memory dump of 256 bytes starting at pointer address 7EFADFA0:
B0 04 02 00 01 00 00 00 07 00 00 00 4D 00 4F 00 4D 00 2E 00 65 00 78 00 65 00 00 00 13 6D B4 FB
80 80 80 80 80 80 80 80 00 00 00 00 F1 EE FA 7E 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
01 05 00 00 E2 43 40 00 C3 4F 40 00 5A 55 40 00 82 61 45 00 96 53 4B 00 7B 18 48 00 E0 DC 43 00
11 DF 43 00 43 E9 43 00 C2 E1 43 00 30 E1 43 00 AC 0D 00 00 E1 4F 40 00 A5 55 40 00 EB 61 45 00
27 50 40 00 E9 55 4B 00 06 19 48 00 C9 55 4B 00 7B 09 48 00 8A 1F 48 00 C9 55 4B 00 D1 69 4D 00
AC 0D 00 00 1C 00 00 00 DC F8 44 00 C8 1C 3B 85 64 12 50 00 80 80 80 80 80 80 80 80 80 80 80 80
80 80 80 80 80 80 80 80 80 80 80 80 37 E3 C4 7A 80 80 80 80 80 80 80 80 00 00 00 00 D0 8B FA 7E
00 00 00 00 00 00 00 00 D8 E9 40 00 00 00 00 00 EB 13 00 00 E2 43 40 00 C7 74 40 00 04 6C 40 00
  . . . . . . . . . . . M . O . M . . . e . x . e . . . . m  
                . . . .       ~  . . . . . . . . . . . . . . . .
. . . .   C @  .   O @  . Z U @  .   a E .   S K . {  . H .     C .
.   C . C   C .     C . 0    C .   . . .   O @  .   U @  .   a E .
' P @  .   U K . . . H .   U K . {  . H .   . H .   U K .   i M .
  . . . . . . .     D .   . ;   d . P .                      
                        7      z                 . . . .       ~
. . . . . . . .     @  . . . . .   . . .   C @  .   t @  . . l @  .

--------------------------------2011/5/9 18:32:23--------------------------------
A memory block has been leaked. The size is: 36

This block was allocated by thread 0xDAC, and the stack trace (return addresses) at the time was:
4043E2 
4074C7 
406C04 
4E4C00 
4E4AB4 
405027 
4EF230 
4EF322 
41E266 
4D7837 
4D7473 

The block is currently used for an object of class: UnicodeString

The allocation number is: 5099

Current memory dump of 256 bytes starting at pointer address 7EFAE100:
B0 04 02 00 01 00 00 00 07 00 00 00 64 00 77 00 6D 00 2E 00 65 00 78 00 65 00 00 00 34 E3 88 FB
80 80 80 80 80 80 80 80 00 00 00 00 F1 E3 FA 7E 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
23 04 00 00 E2 43 40 00 C3 4F 40 00 5A 55 40 00 CB 18 4C 00 B6 0C 4B 00 79 53 4B 00 E0 DA 4B 00
3F 19 47 00 E0 DC 43 00 11 DF 43 00 43 E9 43 00 AC 0D 00 00 E1 4F 40 00 A5 55 40 00 B5 8D 43 00
27 50 40 00 39 0E 4B 00 E1 4F 40 00 A5 55 40 00 B5 8D 43 00 19 56 4B 00 3E DB 4B 00 C9 55 4B 00
AC 0D 00 00 24 00 00 00 88 4E 4A 00 99 96 3D 85 64 12 50 00 80 80 80 80 80 80 80 80 80 80 80 80
80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 66 69 C2 7A 00 00 00 00 C1 DD FA 7E
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 81 03 00 00 E2 43 40 00 C7 74 40 00 04 6C 40 00
  . . . . . . . . . . . d . w . m . . . e . x . e . . . 4     
                . . . .       ~  . . . . . . . . . . . . . . . .
#  . . .   C @  .   O @  . Z U @  .   . L .   . K . y S K .     K .
?  . G .     C . .   C . C   C .   . . .   O @  .   U @  .     C .
' P @  . 9  . K .   O @  .   U @  .     C . . V K . >   K .   U K .
  . . . $  . . .   N J .     =   d . P .                      
                                        f i   z . . . .       ~
. . . . . . . . . . . . . . . .   . . .   C @  .   t @  . . l @  .

--------------------------------2011/5/9 18:32:23--------------------------------
A memory block has been leaked. The size is: 36

This block was allocated by thread 0xDAC, and the stack trace (return addresses) at the time was:
4043E2 
4074C7 
406C04 
4E4C00 
4E4AB4 
405027 
4EF230 
4EF322 
41E266 
4D7837 
4D7473 

The block is currently used for an object of class: UnicodeString

The allocation number is: 5180

Current memory dump of 256 bytes starting at pointer address 7EFAE310:
B0 04 02 00 01 00 00 00 0B 00 00 00 6D 00 73 00 73 00 65 00 63 00 65 00 73 00 2E 00 65 00 78 00
65 00 00 00 BB DE 88 FB 00 00 00 00 F1 F9 FA 7E 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
7D 05 00 00 E2 43 40 00 C3 4F 40 00 5A 55 40 00 BB 06 4B 00 46 56 45 00 99 0C 4B 00 80 CF 4B 00
27 86 46 00 E0 DC 43 00 11 DF 43 00 43 E9 43 00 AC 0D 00 00 E1 4F 40 00 A5 55 40 00 B5 8D 43 00
27 50 40 00 0E 0E 4B 00 E1 4F 40 00 A5 55 40 00 7D 05 4B 00 ED CF 4B 00 C9 55 4B 00 3E DB 4B 00
AC 0D 00 00 24 00 00 00 20 4C 4A 00 34 DB 3D 85 64 12 50 00 80 80 80 80 80 80 80 80 80 80 80 80
80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 CB 24 C2 7A 00 00 00 00 01 E6 FA 7E
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 22 04 00 00 E2 43 40 00 C3 4F 40 00 5A 55 40 00
  . . . . . . . . . . . m . s . s . e . c . e . s . . . e . x .
e . . .         . . . .       ~  . . . . . . . . . . . . . . . .
}  . . .   C @  .   O @  . Z U @  .   . K . F V E .   . K .     K .
'   F .     C . .   C . C   C .   . . .   O @  .   U @  .     C .
' P @  . . . K .   O @  .   U @  . }  . K .     K .   U K . >   K .
  . . . $  . . .    L J . 4    =   d . P .                      
                                          $    z . . . . .     ~
. . . . . . . . . . . . . . . . " . . .   C @  .   O @  . Z U @  .

--------------------------------2011/5/9 18:32:24--------------------------------
A memory block has been leaked. The size is: 36

This block was allocated by thread 0xDAC, and the stack trace (return addresses) at the time was:
4043E2 
4074C7 
406AD8 
4E5878 
4EFBDA
4EF33D
41E266 
4D7837 
4D7473 
4055C8 
4D7448 

The block is currently used for an object of class: UnicodeString

The allocation number is: 57121

Current memory dump of 256 bytes starting at pointer address 7EFAFDE0:
B0 04 02 00 01 00 00 00 06 00 00 00 40 00 20 00 43 00 50 00 55 00 31 00 00 00 90 2B 91 7A 80 80
80 80 80 80 80 80 80 80 00 00 00 00 91 CC FA 7E 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
58 10 00 00 E2 43 40 00 C7 74 40 00 04 6C 40 00 ED EC 43 00 87 E8 43 00 1E DA 43 00 65 ED 43 00
87 E8 43 00 4E E1 43 00 01 E1 43 00 CE 41 44 00 AC 0D 00 00 DD 62 40 00 E9 78 40 00 31 78 40 00
97 50 40 00 DA 4F 40 00 A5 55 40 00 6C 3F 48 00 27 50 40 00 D1 94 43 00 8F 93 43 00 27 50 40 00
AC 0D 00 00 16 00 00 00 B0 04 02 00 F5 2E B0 84 64 12 50 00 80 80 80 80 80 80 80 80 80 80 80 80
80 80 80 80 80 80 0A D1 4F 7B 80 80 80 80 80 80 80 80 80 80 80 80 80 80 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  . . . . . . . . . . . @  .    . C . P . U . 1  . . .   +    z  
                . . . .       ~  . . . . . . . . . . . . . . . .
X . . .   C @  .   t @  . . l @  .     C .     C . .   C . e   C .
    C . N   C . .   C .   A D .   . . .   b @  .   x @  . 1  x @  .
  P @  .   O @  .   U @  . l ?  H . ' P @  .     C .     C . ' P @  .
  . . . . . . .   . . .   .     d . P .                      
            .   O {                              . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

--------------------------------2011/5/9 18:32:24--------------------------------
This application has leaked memory. The small block leaks are (excluding expected leaks registered by pointer):

21 - 36 bytes: UnicodeString x 272
37 - 52 bytes: UnicodeString x 308
69 - 84 bytes: TStringList x 32, UnicodeString x 28
213 - 244 bytes: Unknown x 32

Note: Memory leak detail is logged to a text file in the same folder as this application. To disable this memory leak check, undefine "EnableMemoryLeakReporting".


Die UnicodeStrings nicht so gravierend, oder?

nuclearping 9. Mai 2011 18:05

AW: Hilfestellung zu meinem Speicherleck
 
Wenn du noch Debugging Informationen in das Programm linkst (Projekt-Einstellungen), kannst du den Stack Trace sehen und damit auch, wo die TStringList(en) angelegt werden. Aber SO werden auch wir daraus nicht schlau. ;)

delphinub23 9. Mai 2011 18:11

AW: Hilfestellung zu meinem Speicherleck
 
Liste der Anhnge anzeigen (Anzahl: 1)
Laut Projekt-Einstellungen sind dieses bereits aktiviert?!


EDIT: Achso, habs gefunden. Sorry :D

delphinub23 9. Mai 2011 18:16

AW: Hilfestellung zu meinem Speicherleck
 
Hier die verbesserte Log-Datei (nur ein Ausschnitt der TStringList):

Code:
--------------------------------2011/5/9 19:14:08--------------------------------
A memory block has been leaked. The size is: 84

This block was allocated by thread 0x1288, and the stack trace (return addresses) at the time was:
4043E2 [System.pas][System][@GetMem][2979]
404FC3 [System.pas][System][TObject.NewInstance][9433]
40555A [System.pas][System][@ClassCreate][10277]
43B692 [Classes.pas][Classes][TStringList.Create][5788]
75821438 [CloseHandle]
4E4AE0 [..\Source\ProcessHandler.pas][ProcessHandler][TProcessHandler.GetAllRunningProcs][278]
4E4A5D [..\Source\ProcessHandler.pas][ProcessHandler][TProcessHandler.SetGlobalProcessesAffinity][262]
4EF242 [..\Source\FmMulticorerModule.pas][FmMulticorerModule][TFmMainModule.FormCreate][206]
41E25E [SysUtils][TThreadLocalCounter.Open]
4D77C3 [Forms.pas][Forms][TCustomForm.DoCreate][3319]
4D73FF [Forms.pas][Forms][TCustomForm.AfterConstruction][3203]

The block is currently used for an object of class: TStringList

The allocation number is: 9385

Current memory dump of 256 bytes starting at pointer address 7EF8B4A0:
20 F8 42 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 D0 28 E0 7E
36 00 00 00 3C 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 B9 D4 5D 05 80 80 80 80 80 80 80 80 00 00 00 00 E0 4B F8 7E
00 00 00 00 00 00 00 00 D0 E9 40 00 00 00 00 00 DB 24 00 00 E2 43 40 00 C7 74 40 00 04 6C 40 00
5E 4B 4E 00 5D 4A 4E 00 42 F2 4E 00 5E E2 41 00 C3 77 4D 00 FF 73 4D 00 C8 55 40 00 D4 73 4D 00
88 12 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 4E 00 00 00 00 00 00 00 E7 1A 51 82
B0 04 02 00 01 00 00 00 20 00 00 00 46 00 6C 00 61 00 73 00 68 00 55 00 74 00 69 00 6C 00 36 00
     B . . . . . . . . . . . . . . . . . . . . . . . . .   (    ~
6  . . . < . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . .     ] . &#8364; &#8364; &#8364; &#8364; &#8364; &#8364; &#8364; &#8364; . . . .   K   ~
. . . . . . . .     @  . . . . .   $  . .   C @  .   t @  . . l @  .
^  K N . ] J N . B   N . ^    A .   w M .   s M .   U @  .   s M .
&#710; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . N . . . . . . .   . Q &#8218;
  . . . . . . .    . . . F . l . a . s . h . U . t . i . l . 6  .


EDIT:

Ich glaube das Problem bezieht sich auf meine Funktion in der ich die Prozesse auslese und ich eine TStringList speicher...

Delphi-Quellcode:
function TProcessHandler.GetAllRunningProcs: TStringList;
// returns all currently running processes
var
  s: string;
  sl: TStringList;
  User: string;
begin
  Result := nil;
//  User := GetEnvironmentVariable('USERNAME');
  sl := TStringList.Create;
  try
    hProcSnap := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    if (hProcSnap <> INVALID_HANDLE_VALUE) then
    begin
      pe32.dwSize := SizeOf(ProcessEntry32);
      if (Process32First(hProcSnap, pe32)) then
      begin
        s := pe32.szExeFile;
//        if GetUsernameByExeName(s) = User then
          sl.Add(s);
        while Process32Next(hProcSnap, pe32) do
        begin
          s := pe32.szExeFile;
//          if GetUsernameByExeName(s) = User then
            sl.Add(s);
        end;
      end;
      Result := sl;
    end;
    CloseHandle(hProcSnap);
  finally
    sl := nil;
    sl.Free;
  end;
end;

Bin ich auf dem richtigen Weg?

DeddyH 9. Mai 2011 18:18

AW: Hilfestellung zu meinem Speicherleck
 
Es scheint, dass Du immer wieder Stringlisten anlegst, ohne diese wieder freizugeben.

alfold 9. Mai 2011 18:18

AW: Hilfestellung zu meinem Speicherleck
 
Zitat:

in meinem Projekt arbeitet ich mit einem array aus TStringLists, welche ihren Inhalt aus verschiedenen Funktionen - Timer 3 sek Intervall - zugewiesen bekommen.
Das ist nun mal normal, wenn man alle 3 sek neue Strings hinzufgt. Kommt auch auf die lnge an.

Was erwartest Du also, das der Speicher leer bleibt?
Frage: Was soll es bezwecken alle 3sec was in eine stringliste zu schreiben?

Evtl erzeugst Du auch jedesmal Neue Stringlisten usw.
Solltest evtl mal die Routinen posten die Du erstellt hast.

Gruss aldold

DeddyH 9. Mai 2011 18:22

AW: Hilfestellung zu meinem Speicherleck
 
Zitat:

Delphi-Quellcode:
  finally
    sl := nil;
    sl.Free;
  end;

berleg einmal, was Du hier machst. Selbst, wenn Du es umdrehst, bekommst Du Kummer, da ja dann Result freigegeben wurde. Mach besser aus der Funktion eine Prozedur, die die Stringliste als Parameter entgegennimmt und befllt.

delphinub23 9. Mai 2011 18:25

AW: Hilfestellung zu meinem Speicherleck
 
Das ist meine Routine, die die TStringlists (Global definiert und einmal Form.Create angelegt -- Form.Destroy zerstrt diese auch wieder) bentigt.

Delphi-Quellcode:
procedure TFmMainModule.InitializeListview(const Processes: TStrings; const PIDs: TStrings; const Affinities: TStrings);
var
  Index: integer;
  i: Integer;
begin
  try
    lvProcessList.Items.BeginUpdate;
    try
      lvProcessList.Clear;
      ImageList.Clear;
      // reset TImageList index value
      Index := 0;

      // get processes
      ProcessInformation[0] := Processes;
      // pids
      ProcessInformation[1] := PIDs;
      // affinities
      ProcessInformation[2] := Affinities;
      // icons
      for i := 0 to Pred(ProcessInformation[0].Count) do
      begin
        SetExeIconToImageList(Imagelist, Index, StrToInt(PIDs.Strings[i]));
        Inc(Index);
      end;
    finally
      lvProcessList.Items.Count := ProcessInformation[0].Count;
      lvProcessList.AlphaSort;
      lvProcessList.Items.EndUpdate;
    end;
  except
    MessageDlg('Could not initialize application!', mtError, [mbOk], 0);
    Application.Terminate;
  end;
end;

@ DeddyH:
Zitat:

Zitat:
Delphi-Quellcode:
   finally
     sl := nil;
     sl.Free;
   end;

Wenn ich nur .Free rufe, dann bekomme ich eine Exception. Darum diese komische Variante :(

DeddyH 9. Mai 2011 18:28

AW: Hilfestellung zu meinem Speicherleck
 
Und was hat das mit der oben geposteten Routine zu tun?

delphinub23 9. Mai 2011 18:32

AW: Hilfestellung zu meinem Speicherleck
 
Na die obere Routine besorgt die Prozesse als TStringList. Die bergebe ich dann an eine weitere Funktion, die die Prozesse filtert (UserName).

Das Resultat bergebe ich dann an die zuletzt gepostete Routine.


Wieso verbraucht meine Applikation immer mehr Speicher?

DeddyH 9. Mai 2011 18:36

AW: Hilfestellung zu meinem Speicherleck
 
Nochmal: GetAllRunningProcs erzeugt je Aufruf eine neue Instanz von TStringlist. Ich sehe aber nicht, wo diese wieder freigegeben wird. Daher mein Rat, die Liste auerhalb zu erzeugen und an die Routine zu bergeben, dann kannst Du sie auch wieder freigeben, da Du es nur mit einer Instanz zu tun hast.

delphinub23 9. Mai 2011 18:40

AW: Hilfestellung zu meinem Speicherleck
 
Moment, ich kann dir gerade nicht folgen:

Meine erzeugte TStringList wird doch am Ende freigegeben, oder etwa nicht?

Delphi-Quellcode:
function TProcessHandler.GetAllRunningProcs: TStringList;
// returns all currently running processes
var
  s: string;
  sl: TStringList;
begin
  Result := nil;
  sl := TStringList.Create;  // <--- HIER erzeuge ich es...
  try
    hProcSnap := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    if (hProcSnap <> INVALID_HANDLE_VALUE) then
    begin
      pe32.dwSize := SizeOf(ProcessEntry32);
      if (Process32First(hProcSnap, pe32)) then
      begin
        s := pe32.szExeFile;
        sl.Add(s);
        while Process32Next(hProcSnap, pe32) do
        begin
          s := pe32.szExeFile;
          sl.Add(s);
        end;
      end;
      Result := sl;
    end;
    CloseHandle(hProcSnap);
  finally
    sl := nil; // <--- HIER &
    sl.Free;   // <--- HIER wirds doch wieder gelscht?
  end;
end;

DeddyH 9. Mai 2011 18:44

AW: Hilfestellung zu meinem Speicherleck
 
Du setzt sie doch vorher auf nil, wie willst Du sie denn wieder freigeben? Wie gesagt, wenn Du die Befehle umdrehst zeigt Result dann nach dem Freigeben auf eine nicht mehr existente Instanz, das ist also auch nicht die Lsung. Versuch es doch einmal so:
Delphi-Quellcode:
procedure TProcessHandler.GetAllRunningProcs(ResultList: TStrings);
// returns all currently running processes
var
  s: string;
//  User: string;
begin
// User := GetEnvironmentVariable('USERNAME');
  if Assigned(ResultList) then
    begin
      ResultList.BeginUpdate;
      try
        ResultList.Clear;
        hProcSnap := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
        if (hProcSnap <> INVALID_HANDLE_VALUE) then
        begin
          pe32.dwSize := SizeOf(ProcessEntry32);
          if (Process32First(hProcSnap, pe32)) then
          begin
            s := pe32.szExeFile;
    // if GetUsernameByExeName(s) = User then
              ResultList.Add(s);
            while Process32Next(hProcSnap, pe32) do
            begin
              s := pe32.szExeFile;
    // if GetUsernameByExeName(s) = User then
                ResultList.Add(s);
            end;
          end;
        end;
        CloseHandle(hProcSnap);
      finally
        ResultList.EndUpdate;
      end;
    end;
end;
Der Prozedur bergibst Du dann einfach die zu fllende Stringliste.

delphinub23 9. Mai 2011 18:49

AW: Hilfestellung zu meinem Speicherleck
 
Achso, danke DeddyH. Du hast natrlich Recht...nun hab ich es auch verstanden :oops:
Eine Frage noch: Die GetAllProcs-procedure befindet sich in einer eigenen Klasse. Sollte ich das Resultat als property oder als richtiges Result zurckgeben? Oder gar nicht und die Procedure in die MainForm bernehemen?

DeddyH 9. Mai 2011 18:58

AW: Hilfestellung zu meinem Speicherleck
 
Die Frage verstehe ich nicht. Je nachdem, ob die Methode ffentlich ist oder nicht, kann sie ja von auen aufgerufen werden. Ist sie nur intern, kannst Du natrlich auch den ResultList-Parameter weglassen und stattdessen gleich die Stringliste der Klasse dafr einsetzen.

delphinub23 9. Mai 2011 19:01

AW: Hilfestellung zu meinem Speicherleck
 
Ich bedanke mich bei allen Helfern, ganz besonderns dir DeddyH. Ich wei was ich nun machen muss :)

nuclearping 10. Mai 2011 11:23

AW: Hilfestellung zu meinem Speicherleck
 
Zitat:

Zitat von delphinub23 (Beitrag 1099818)
@ DeddyH:
Zitat:

Zitat:
Delphi-Quellcode:
   finally
     sl := nil;
     sl.Free;
   end;

Wenn ich nur .Free rufe, dann bekomme ich eine Exception. Darum diese komische Variante :(

Du bekommst die Exception, weil du in der Funktion Result die TStringList sl zuweist. Result := sl. Result und sl sind damit das gleiche, das gleiche Objekt, der gleiche Speicher. Wenn du nun sl.Free machst, machst du auch gleichzeitig Result.Free und deswegen hats geknallt.

DeddyH 10. Mai 2011 12:08

AW: Hilfestellung zu meinem Speicherleck
 
Korrekt, das hatte ich ja auch bereits 2 mal erklrt ;)


Alle Zeitangaben in WEZ +1. Es ist jetzt 10:15 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz