Delphi-PRAXiS
Seite 3 von 3     123   

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)

Kas Ob. 7. Dez 2023 08:15

AW: Speicherproblem mit Objekten in DLL
 
@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.

BastiFantasti 7. Dez 2023 13:45

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 könntest, 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 8-)

BastiFantasti 8. Dez 2023 13:02

AW: Speicherproblem mit Objekten in DLL
 
Das Problem ist behoben.
Es war ein nicht freigegebenes JSON Objekt bei der Objektserialisierung.

Für 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 :oops:
d.h. der Fehler war nicht bei Delphi zu suchen, sondern 40cm vor dem Bildschirm.

hoika 8. Dez 2023 14:42

AW: Speicherproblem mit Objekten in DLL
 
Hallo,
hätte FastMM4 nicht wenigstens das Objekt anzeigen müssen?

jaenicke 8. Dez 2023 17:34

AW: Speicherproblem mit Objekten in DLL
 
Zitat:

Zitat von hoika (Beitrag 1530588)
Hallo,
hätte FastMM4 nicht wenigstens das Objekt anzeigen müssen?

Das schon, aber ich kann nachvollziehen, dass es hier nicht offensichtlich war, was das Grundproblem war. Denn im Log stand ja (siehe oben) TJSONObject x 345, weil diese in der Json-Struktur mehrfach verwendet werden. Hier dann das oberste zu finden, dazu dann den Stacktrace, ...

Klar, wenn man es dann erst weiß, ist es total logisch, auch dem Threadersteller. Aber wie es halt so ist... wenn man sucht und sucht, in die falsche Richtung schaut, ... Wem ist es noch nicht so ergangen? Mir auf jeden Fall schon oft. Wichtig ist, dass man daraus lernt, so dass man beim nächsten Mal weniger lange sucht.


Alle Zeitangaben in WEZ +1. Es ist jetzt 01:59 Uhr.
Seite 3 von 3     123   

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