Delphi-PRAXiS
Seite 2 von 3     12 3      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   Delphi Speicherproblem mit Objekten in DLL (https://www.delphipraxis.net/214210-speicherproblem-mit-objekten-dll.html)

BastiFantasti 6. Dez 2023 14:06

AW: Speicherproblem mit Objekten in DLL
 
Zitat:

Zitat von Sinspin (Beitrag 1530476)
Du bergibst der Dll Funktion den String? Um Spass mit langen Strings zu vermeiden verwende ich fr die Kommunikation mit Dll's Named Pipes oder gleich einen Netzwerk Socket.

Der bergabeparameter an die DLL ist nur ein Record in dieser Form:


Code:
  RFTPEventStr = Record

    // event info
    Event: Longword; // event code
    SubEvent: Longword; // sub-event code

    // user info
    SessionID: Longword; // unique ID of the FTP session
    User: array [0 .. 39] of AnsiChar; // user name
    ClientIP: array [0 .. 15] of AnsiChar; // IP number of client
    LocalIP: array [0 .. 15] of AnsiChar; // IP number the client connected to

    // event attributes
    Duration: Longword; // duration of events (in seconds)
    Size: Longword; // size of object (i.e. file)

    // hook info
    hWindow: word; // window handle to post decision to
    Message: longint; // message to post
    pReplyText: PAnsiChar; // pointer to text to send to user
    AuxOne: array [0 .. 511] of AnsiChar; // auxiliary area one
    AuxTwo: array [0 .. 511] of AnsiChar; // auxiliary area two

  end;
Das ist soweit aber iO. Die Daten aus dem Objekt werden nur innerhalb der DLL verwendet, also nicht an die Hostanwendung durchgereicht.

BastiFantasti 6. Dez 2023 14:27

AW: Speicherproblem mit Objekten in DLL
 
Liste der Anhnge anzeigen (Anzahl: 1)
Hier mal noch ein Bild von dem Problem im Anhang.

Ich verwende die ganzen TJsonArray, TJSonPair usw alle nur indirekt.

Ich erzeuge mir mein Delphiobjekt ber die integrierten Funktionen:

Code:
result := TJson.JsonToObject<TMyObject>(js);
js ist der String mit dem nach JSON serialisierten Delphi Objekt.

Die Funktion TJson.JsonToObject ist aus der REST.Json unit

BastiFantasti 6. Dez 2023 14:56

AW: Speicherproblem mit Objekten in DLL
 
Wenn ich die Meldungen richtig interpretiere, leakt nicht mein Objekt den Speicher, sondern das Deserialisieren des JSON Strings in das entsprechende Objekt...

Sinspin 6. Dez 2023 15:40

AW: Speicherproblem mit Objekten in DLL
 
Das leakt auch wenn nur in der Exe aufgerufen? Wenn nicht, wrde mich wundern wenn ein anderes Verhalten fr Dll implementiert worden wre. (wie auch immer das gehen sollte)

Zitat:

Zitat von jaenicke (Beitrag 1530477)
Zitat:

Zitat von Sinspin (Beitrag 1530476)
Du bergibst der Dll Funktion den String? Um Spass mit langen Strings zu vermeiden verwende ich fr die Kommunikation mit Dll's Named Pipes oder gleich einen Netzwerk Socket.

Wozu der Aufwand? WideStrings knnen z.B. Strings mit bis zu ca. 2^30 Zeichen enthalten. Und wenn du dann noch ein Interface verwendest, hast du eine schne Schnittstelle.

Ja, das musst Du schon beantworten. Wozu soll ich mir den Aufwand machen und mich mit Interfaces belasten?
Ich kann mit einem Modul alle beliebigen Daten bertragen die ich will. Eine serialisierbare Memtable kmmert sich intern um alles ntige zur Datenverwaltung. Einmal eingebunden kann ich mit allen Modulen kommunizieren. Egal ob auf einem Rechner, zwischen Diensten, zwischen Rechnern, bers Internet. Selbst broadcast.

BastiFantasti 6. Dez 2023 17:44

AW: Speicherproblem mit Objekten in DLL
 
Die Andere Art der Datenbergabe in eine DLL ist sicher eine gute Idee, leider sind mir hier die Hnde gebunden.

Ich konnte das Problem jetzt in der Tat auch rein in der Exe nachstellen. Keine Ahnung warum sich das Verhalten seither nicht ebenso in der Exe gezeigt hat.
Aber umso besser. Das macht es nun leichter zu debuggen und einzuschtzen (hoffentlich).

Nach einem Durchlauf mit einem Speicherleck von ein paar MB schreibt FastMM4 mir nun schon eine 100MB groe Eventlog Datei :shock:

Spter dazu mehr

BastiFantasti 6. Dez 2023 17:52

AW: Speicherproblem mit Objekten in DLL
 
Hier mal ein paar Elemente aus dem Eventlog:

Code:
--------------------------------2023/12/6 18:41:38--------------------------------
A memory block has been leaked. The size is: 20

This block was allocated by thread 0x32A4, and the stack trace (return addresses) at the time was:
CD781E [System.pas][System][@GetMem$qqri][4949]
F38C6A [System.Generics.Collections.pas][REST.JsonReflect][Jsonreflect.%TTypeMarshaller__1$p22System.Json.TJSONValue%.MarshalValue][3405]
F38E96 [System.Generics.Collections.pas][REST.JsonReflect][Jsonreflect.%TTypeMarshaller__1$p22System.Json.TJSONValue%.MarshalValue][3454]
F377FB [System.Generics.Collections.pas][REST.JsonReflect][Jsonreflect.%TTypeMarshaller__1$p22System.Json.TJSONValue%.MarshalSimpleField][3689]
F38993 [System.Generics.Collections.pas][REST.JsonReflect][Jsonreflect.%TTypeMarshaller__1$p22System.Json.TJSONValue%.MarshalData][3622]
F38E23 [System.Generics.Collections.pas][REST.JsonReflect][Jsonreflect.%TTypeMarshaller__1$p22System.Json.TJSONValue%.MarshalValue][3438]
F3763F [System.Generics.Collections.pas][REST.JsonReflect][Jsonreflect.%TTypeMarshaller__1$p22System.Json.TJSONValue%.MarshalSimpleField][3648]
F3897A [System.Generics.Collections.pas][REST.JsonReflect][Jsonreflect.%TTypeMarshaller__1$p22System.Json.TJSONValue%.MarshalData][3615]
F39F26 [System.Generics.Collections.pas][REST.JsonReflect][Jsonreflect.%TTypeMarshaller__1$p22System.Json.TJSONValue%.Marshal][3179]
F3EF33 [REST.Json.pas][REST.Json][Json.TJson.ObjectToJsonValue][202]
F3EF8D [REST.Json.pas][REST.Json][Json.TJson.ObjectToJsonObject][214]

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

The allocation number is: 700365

Current memory dump of 256 bytes starting at pointer address 9458460:
A8 28 F0 00 01 00 00 00 BC DE 4A 07 00 00 00 00 00 00 00 00 4C 57 3E E0 00 00 00 00 E0 18 45 09
00 00 00 00 00 00 00 00 78 CF CE 00 00 00 00 00 CB AF 0A 00 1E 78 CD 00 6A 8C F3 00 96 8E F3 00
FB 77 F3 00 93 89 F3 00 23 8E F3 00 3F 76 F3 00 7A 89 F3 00 26 9F F3 00 33 EF F3 00 8D EF F3 00
A4 32 00 00 A4 32 00 00 3A 78 CD 00 4B 1D CE 00 47 E8 CD 00 0B 01 CE 00 13 40 F3 00 68 41 F3 00
DF FD F2 00 2E CB F2 00 73 C7 F2 00 50 FD F2 00 2E CB F2 00 14 00 00 00 74 46 74 01 51 A9 C1 1F
A8 28 F0 00 01 00 00 00 5C 88 0A 09 00 00 00 00 00 00 00 00 AE 56 3E E0 00 00 00 00 E0 18 45 09
00 00 00 00 00 00 00 00 78 CF CE 00 00 00 00 00 C9 AF 0A 00 1E 78 CD 00 6A 8C F3 00 96 8E F3 00
FB 77 F3 00 93 89 F3 00 23 8E F3 00 3F 76 F3 00 7A 89 F3 00 26 9F F3 00 33 EF F3 00 8D EF F3 00
  (    . . . . .     J . . . . . . . . . L W >   . . . .   . E .
. . . . . . . . x     . . . . .     . . . x   . j     .       .
  w   .       . #      . ?  v   . z     . &     . 3      .       .
  2  . .   2  . . : x   . K .   . G     . . .   . . @    . h A   .
      . .     . s     . P     . .     . . . . . t F t . Q     .
  (    . . . . . \    . . . . . . . . . .   V >   . . . .   . E .
. . . . . . . . x     . . . . .     . . . x   . j     .       .
  w   .       . #      . ?  v   . z     . &     . 3      .       .

Code:
--------------------------------2023/12/6 18:41:39--------------------------------
A memory block has been leaked. The size is: 180

This block was allocated by thread 0x32A4, and the stack trace (return addresses) at the time was:
CD781E [System.pas][System][@GetMem$qqri][4949]
F0BF0C [System.JSON.pas][System.JSON][Json.TJSONValue.ParseString][2089]

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

The allocation number is: 109337

Current memory dump of 256 bytes starting at pointer address 90A7E50:
B0 04 02 00 01 00 00 00 4E 00 00 00 32 00 30 00 32 00 33 00 2D 00 31 00 32 00 2D 00 30 00 36 00
20 00 31 00 38 00 3A 00 34 00 30 00 3A 00 34 00 35 00 3A 00 20 00 53 00 65 00 74 00 20 00 54 00
61 00 73 00 6B 00 20 00 53 00 65 00 74 00 75 00 70 00 20 00 54 00 69 00 6D 00 65 00 20 00 28 00
55 00 54 00 43 00 29 00 20 00 32 00 30 00 32 00 33 00 2D 00 31 00 32 00 2D 00 30 00 36 00 20 00
31 00 37 00 3A 00 34 00 30 00 3A 00 34 00 35 00 20 00 55 00 54 00 43 00 20 00 28 00 36 00 30 00
6D 00 69 00 6E 00 29 00 00 00 26 9D 66 F4 79 01 84 5F 79 01 84 5F 79 01 00 00 00 00 70 72 0A 09
00 00 00 00 00 00 00 00 78 CF CE 00 00 00 00 00 1B AB 01 00 1E 78 CD 00 0C BF F0 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
  . . . . . . . N . . . 2  . 0  . 2  . 3  . -  . 1  . 2  . -  . 0  . 6  .
   . 1  . 8  . : . 4  . 0  . : . 4  . 5  . : .    . S . e . t .    . T .
a . s . k .    . S . e . t . u . p .    . T . i . m . e .    . (  .
U . T . C . ) .    . 2  . 0  . 2  . 3  . -  . 1  . 2  . -  . 0  . 6  .    .
1  . 7  . : . 4  . 0  . : . 4  . 5  .    . U . T . C .    . (  . 6  . 0  .
m . i . n . ) . . . &   f   y .   _  y .   _  y . . . . . p r . .
. . . . . . . . x     . . . . . .   . . . x   . .     . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Code:
--------------------------------2023/12/6 18:41:39--------------------------------
A memory block has been leaked. The size is: 20

This block was allocated by thread 0x32A4, and the stack trace (return addresses) at the time was:
CD781E [System.pas][System][@GetMem$qqri][4949]
F2AE46 [REST.JsonReflect.pas][REST.JsonReflect][Jsonreflect.TJSONConverter.OnFieldStart][1238]
F37665 [System.Generics.Collections.pas][REST.JsonReflect][Jsonreflect.%TTypeMarshaller__1$p22System.Json.TJSONValue%.MarshalSimpleField][3654]
F38993 [System.Generics.Collections.pas][REST.JsonReflect][Jsonreflect.%TTypeMarshaller__1$p22System.Json.TJSONValue%.MarshalData][3622]
F38E23 [System.Generics.Collections.pas][REST.JsonReflect][Jsonreflect.%TTypeMarshaller__1$p22System.Json.TJSONValue%.MarshalValue][3438]
F38E96 [System.Generics.Collections.pas][REST.JsonReflect][Jsonreflect.%TTypeMarshaller__1$p22System.Json.TJSONValue%.MarshalValue][3454]
F377FB [System.Generics.Collections.pas][REST.JsonReflect][Jsonreflect.%TTypeMarshaller__1$p22System.Json.TJSONValue%.MarshalSimpleField][3689]
F38993 [System.Generics.Collections.pas][REST.JsonReflect][Jsonreflect.%TTypeMarshaller__1$p22System.Json.TJSONValue%.MarshalData][3622]
F38E23 [System.Generics.Collections.pas][REST.JsonReflect][Jsonreflect.%TTypeMarshaller__1$p22System.Json.TJSONValue%.MarshalValue][3438]
F3763F [System.Generics.Collections.pas][REST.JsonReflect][Jsonreflect.%TTypeMarshaller__1$p22System.Json.TJSONValue%.MarshalSimpleField][3648]
F3897A [System.Generics.Collections.pas][REST.JsonReflect][Jsonreflect.%TTypeMarshaller__1$p22System.Json.TJSONValue%.MarshalData][3615]

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

The allocation number is: 559108

Current memory dump of 256 bytes starting at pointer address 90B60F0:
0C 2F F0 00 01 00 00 00 50 60 0B 09 B0 5F 0B 09 00 00 00 00 FE 38 7B E1 00 00 00 00 D0 58 0B 09
00 00 00 00 00 00 00 00 78 CF CE 00 00 00 00 00 EF 87 08 00 1E 78 CD 00 93 89 F3 00 23 8E F3 00
96 8E F3 00 FB 77 F3 00 93 89 F3 00 23 8E F3 00 3F 76 F3 00 7A 89 F3 00 26 9F F3 00 33 EF F3 00
A4 32 00 00 A4 32 00 00 3A 78 CD 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 10 00 00 00 A8 28 F0 00 DE FA F1 15
58 42 F0 00 01 00 00 00 01 00 00 00 00 00 00 00 21 05 0E EA 84 5F 79 01 00 00 00 00 D0 58 0B 09
00 00 00 00 00 00 00 00 78 CF CE 00 00 00 00 00 EC 87 08 00 1E 78 CD 00 46 AE F2 00 65 76 F3 00
93 89 F3 00 23 8E F3 00 96 8E F3 00 FB 77 F3 00 93 89 F3 00 23 8E F3 00 3F 76 F3 00 7A 89 F3 00
. /    . . . . . P `  . .   _  . . . . . .   8  {    . . . .   X . .
. . . . . . . . x     . . . . .     . . . x   .       . #      .
      .   w   .       . #      . ?  v   . z     . &     . 3      .
  2  . .   2  . . : x   . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . .   (    .       .
X B   . . . . . . . . . . . . . !  . .     _  y . . . . .   X . .
. . . . . . . . x     . . . . .     . . . x   . F     . e v   .
      . #      .       .   w   .       . #      . ?  v   . z     .
Code:
--------------------------------2023/12/6 18:41:39--------------------------------
A memory block has been leaked. The size is: 20

This block was allocated by thread 0x32A4, and the stack trace (return addresses) at the time was:
CD781E [System.pas][System][@GetMem$qqri][4949]
F38993 [System.Generics.Collections.pas][REST.JsonReflect][Jsonreflect.%TTypeMarshaller__1$p22System.Json.TJSONValue%.MarshalData][3622]
F38E23 [System.Generics.Collections.pas][REST.JsonReflect][Jsonreflect.%TTypeMarshaller__1$p22System.Json.TJSONValue%.MarshalValue][3438]
F38E96 [System.Generics.Collections.pas][REST.JsonReflect][Jsonreflect.%TTypeMarshaller__1$p22System.Json.TJSONValue%.MarshalValue][3454]
F377FB [System.Generics.Collections.pas][REST.JsonReflect][Jsonreflect.%TTypeMarshaller__1$p22System.Json.TJSONValue%.MarshalSimpleField][3689]
F38993 [System.Generics.Collections.pas][REST.JsonReflect][Jsonreflect.%TTypeMarshaller__1$p22System.Json.TJSONValue%.MarshalData][3622]
F38E23 [System.Generics.Collections.pas][REST.JsonReflect][Jsonreflect.%TTypeMarshaller__1$p22System.Json.TJSONValue%.MarshalValue][3438]
F3763F [System.Generics.Collections.pas][REST.JsonReflect][Jsonreflect.%TTypeMarshaller__1$p22System.Json.TJSONValue%.MarshalSimpleField][3648]
F3897A [System.Generics.Collections.pas][REST.JsonReflect][Jsonreflect.%TTypeMarshaller__1$p22System.Json.TJSONValue%.MarshalData][3615]
F39F26 [System.Generics.Collections.pas][REST.JsonReflect][Jsonreflect.%TTypeMarshaller__1$p22System.Json.TJSONValue%.Marshal][3179]
F3EF33 [REST.Json.pas][REST.Json][Json.TJson.ObjectToJsonValue][202]

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

The allocation number is: 559087

Current memory dump of 256 bytes starting at pointer address 90B6190:
58 42 F0 00 01 00 00 00 01 00 00 00 00 00 00 00 21 05 0E EA 84 5F 79 01 00 00 00 00 D0 58 0B 09
00 00 00 00 00 00 00 00 78 CF CE 00 00 00 00 00 EC 87 08 00 1E 78 CD 00 46 AE F2 00 65 76 F3 00
93 89 F3 00 23 8E F3 00 96 8E F3 00 FB 77 F3 00 93 89 F3 00 23 8E F3 00 3F 76 F3 00 7A 89 F3 00
A4 32 00 00 A4 32 00 00 3A 78 CD 00 35 AE F2 00 65 76 F3 00 93 89 F3 00 23 8E F3 00 96 8E F3 00
FB 77 F3 00 93 89 F3 00 23 8E F3 00 3F 76 F3 00 7A 89 F3 00 14 00 00 00 B0 04 02 00 29 C8 84 1E
A8 28 F0 00 01 00 00 00 3C BC FA 06 00 00 00 00 00 00 00 00 D6 37 7B E1 00 00 00 00 D0 58 0B 09
00 00 00 00 00 00 00 00 78 CF CE 00 00 00 00 00 EB 87 08 00 1E 78 CD 00 46 AE F2 00 65 76 F3 00
93 89 F3 00 23 8E F3 00 96 8E F3 00 FB 77 F3 00 93 89 F3 00 23 8E F3 00 3F 76 F3 00 7A 89 F3 00
X B   . . . . . . . . . . . . . !  . .     _  y . . . . .   X . .
. . . . . . . . x     . . . . .     . . . x   . F     . e v   .
      . #      .       .   w   .       . #      . ?  v   . z     .
  2  . .   2  . . : x   . 5      . e v   .       . #      .       .
  w   .       . #      . ?  v   . z     . . . . .   . . . )     .
  (    . . . . . <     . . . . . . . . .   7  {    . . . .   X . .
. . . . . . . . x     . . . . .     . . . x   . F     . e v   .
      . #      .       .   w   .       . #      . ?  v   . z     .
und hier noch das Summary

Code:

--------------------------------2023/12/6 18:45:08--------------------------------
This application has leaked memory. The small block leaks are:

13 - 20 bytes: TIdThreadSafeInteger x 1, TJSONArray x 2, TJSONObject x 345, TJSONTrue x 1376, TJSONFalse x 1033, TJSONPair x 4480, TJSONString x 18236, TJSONNumber x 691, UnicodeString x 688
21 - 36 bytes: TIdCriticalSection x 2, UnicodeString x 1729, Unknown x 2
37 - 52 bytes: TList<System.JSON.TJSONValue> x 2, TList<System.JSON.TJSONPair> x 345, UnicodeString x 2417
53 - 68 bytes: UnicodeString x 1600
69 - 84 bytes: UnicodeString x 2914
85 - 100 bytes: UnicodeString x 1657
101 - 116 bytes: UnicodeString x 982
117 - 132 bytes: UnicodeString x 1533, Unknown x 342
133 - 148 bytes: UnicodeString x 2230
149 - 164 bytes: UnicodeString x 871
165 - 180 bytes: UnicodeString x 1323
181 - 212 bytes: UnicodeString x 296, Unknown x 1
213 - 244 bytes: UnicodeString x 1
1509 - 1668 bytes: Unknown x 1

The sizes of leaked medium and large blocks are: 59300
Das ist was nach einem Aufruf an Leaks passiert

BastiFantasti 6. Dez 2023 20:08

AW: Speicherproblem mit Objekten in DLL
 
N'Abend

es liegt an der Delphi internen Objektserialisierung / Deserialisierung.
Ich hab nun das Objekt auf die neon library umgesetellt und schon klappts.

Jetzt muss ich mir nur noch berlegen ob ich das so bernehme und wie.
Da hngt jetzt ein riesen Rattenschwanz dran...

Sinspin 7. Dez 2023 06:51

AW: Speicherproblem mit Objekten in DLL
 
Ich kann mir nicht Vorstellen das so ein Problem lange unentdeckt bleiben wrde.
Vermutlich haben das bisher noch nicht viele mit so groen Objekten probiert oder es gibt noch immer Umstnde die Du bisher noch nicht erkannt hast, warum es bei dir so durchschlgt.
Egal wie, es sollte nicht auftreten und ist einen Bugreport wert.

jaenicke 7. Dez 2023 07:35

AW: Speicherproblem mit Objekten in DLL
 
Wenn du (ggf. auch nur mir per PN, das gebe ich nicht weiter) ein Beispiel schicken knntest, kann ich mir das gerne einmal anschauen. Ich benutze die Klassen selbst und habe nicht solche Leaks.

BastiFantasti 7. Dez 2023 07:55

AW: Speicherproblem mit Objekten in DLL
 
Zitat:

Zitat von jaenicke (Beitrag 1530510)
Wenn du (ggf. auch nur mir per PN, das gebe ich nicht weiter) ein Beispiel schicken knntest, kann ich mir das gerne einmal anschauen. Ich benutze die Klassen selbst und habe nicht solche Leaks.

PN ist raus :thumb:


Alle Zeitangaben in WEZ +1. Es ist jetzt 03:36 Uhr.
Seite 2 von 3     12 3      

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