AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Ntzliche Links
Registrieren
Zurck Delphi-PRAXiS Programmierung allgemein Programmieren allgemein Delphi Speicherproblem mit Objekten in DLL

Speicherproblem mit Objekten in DLL

Ein Thema von BastiFantasti · begonnen am 4. Dez 2023 · letzter Beitrag vom 8. Dez 2023
Antwort Antwort
BastiFantasti

Registriert seit: 5. Nov 2014
Ort: Baden Wrttemberg
145 Beitrge
 
Delphi 12 Athens
 
#1

AW: Speicherproblem mit Objekten in DLL

  Alt 6. Dez 2023, 17:44
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

Spter dazu mehr
Bastian
  Mit Zitat antworten Zitat
BastiFantasti

Registriert seit: 5. Nov 2014
Ort: Baden Wrttemberg
145 Beitrge
 
Delphi 12 Athens
 
#2

AW: Speicherproblem mit Objekten in DLL

  Alt 6. Dez 2023, 17:52
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
Bastian
  Mit Zitat antworten Zitat
BastiFantasti

Registriert seit: 5. Nov 2014
Ort: Baden Wrttemberg
145 Beitrge
 
Delphi 12 Athens
 
#3

AW: Speicherproblem mit Objekten in DLL

  Alt 6. Dez 2023, 20:08
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...
Bastian
  Mit Zitat antworten Zitat
Benutzerbild von Sinspin
Sinspin

Registriert seit: 15. Sep 2008
Ort: Dubai
749 Beitrge
 
Delphi 10.3 Rio
 
#4

AW: Speicherproblem mit Objekten in DLL

  Alt 7. Dez 2023, 06:51
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.
Stefan
Nur die Besten sterben jung
A constant is a constant until it change.
  Mit Zitat antworten Zitat
Benutzerbild von jaenicke
jaenicke

Registriert seit: 10. Jun 2003
Ort: Berlin
10.054 Beitrge
 
Delphi 12 Athens
 
#5

AW: Speicherproblem mit Objekten in DLL

  Alt 7. Dez 2023, 07:35
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.
Sebastian Jnicke
AppCentral
  Mit Zitat antworten Zitat
BastiFantasti

Registriert seit: 5. Nov 2014
Ort: Baden Wrttemberg
145 Beitrge
 
Delphi 12 Athens
 
#6

AW: Speicherproblem mit Objekten in DLL

  Alt 7. Dez 2023, 07:55
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
Bastian
  Mit Zitat antworten Zitat
Kas Ob.

Registriert seit: 3. Sep 2023
457 Beitrge
 
#7

AW: Speicherproblem mit Objekten in DLL

  Alt 7. Dez 2023, 08:15
@BastiFantasti , Hi

For me this behavior looks like dangling pointers (by-copy), this of course will leads to memory leak but not exactly as traditional just not-freed.

So my thoughts here:
1) you can increase the stack reported by FastMM for the leaks by adjusting a constant in FastMM4.pas to something like 30, it might help, or you can use EurekaLog as it will report the leaks with far more accuracy, as i can't see if the record (you mentioned in the second post) in the report, did it leak too ?
2) the most crucial thing is to check and then double check, how these record and objects being passed to the DLL, i mean how did you declare the parameters for these managed types or that record, are these "const" or "var" or left as default without modifier, each one will behave differently and this might cause this copy, hence increasing the ref count causing this leak.
3) are doing any sort of casting on managed type or that record? is it passed by pointer or as const ? you can also track its refCount (or any of its managed type field) in memory before calling from the EXE and compare on the DLL after that call.

Hope that helps.
Kas
  Mit Zitat antworten Zitat
BastiFantasti

Registriert seit: 5. Nov 2014
Ort: Baden Wrttemberg
145 Beitrge
 
Delphi 12 Athens
 
#8

AW: Speicherproblem mit Objekten in DLL

  Alt 7. Dez 2023, 13:45
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.
Wollte dir gerade ein PN schicken, aber dein Inbox ist voll
Bastian
  Mit Zitat antworten Zitat
BastiFantasti

Registriert seit: 5. Nov 2014
Ort: Baden Wrttemberg
145 Beitrge
 
Delphi 12 Athens
 
#9

AW: Speicherproblem mit Objekten in DLL

  Alt 8. Dez 2023, 13:02
Das Problem ist behoben.
Es war ein nicht freigegebenes JSON Objekt bei der Objektserialisierung.

Fr die anderen, die auch in diese Verlegenheit kommen:

Code:
var
  jo: System.Json.TJsonObject;
begin
  try
    jo := rest.Json.TJson.ObjectToJsonObject(aObject);
    Result := jo.Format(DEF_JSON_INDENT);
  finally
    freeandnil(jo);
  end;
end;
Hier hatte ich vergessen das TJsonObject freizugeben
d.h. der Fehler war nicht bei Delphi zu suchen, sondern 40cm vor dem Bildschirm.
Bastian
  Mit Zitat antworten Zitat
Antwort Antwort

Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beitrge zu antworten.
Es ist dir nicht erlaubt, Anhnge hochzuladen.
Es ist dir nicht erlaubt, deine Beitrge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 22:00 Uhr.
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