-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
I have a class (TDemoFamily) where I use a TObjectList list to contain TDemoPersonobjects. I want to serialize and deserialize instances of TDemoFamily using DelphiJSON. It works in general, but there are two memory leaks involved, one of which I can handle.
Consider this code:
fam := DelphiJSON<TDemoFamily>.Deserialize(CTest);
fam.members.OwnsObjects := True;
fam.Free; // Leaks a hidden instance of TDemoFamily
When the first statement executes, it returns a properly constructed TDemoFamily, with two caveats:
- The members TObjectList list is created (line 1) with the "OwnsObjects" property set to False, which is unfortunate, as one needs to manually delete the list when deleting the TDemoFamily object. Fortunately, setting it True here (line 2) seems to resolve that, but it is something that needs to be remembered. (Note: the TDemoFamily constructor sets that property True.)
- When you later delete the family (line 3), the leak of a TDemoFamily instance occurs.
I've attached a simple example, a console app that when run, shows the leakage report. Included in the archive is a Hack fix for the other issue I created several days ago.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels