onryldz / x-superobject

Delphi Cross Platform Rapid JSON
316 stars 118 forks source link

Memory leaks with SuperArrays containing SuperObjects #60

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
Create a TSuperArray.
Add a TSuperObject element.  Memory leak on app shutdown even if SA is assigned 
nil explicitly.  Destructor for array elements are not called.

What is the expected output? What do you see instead?
There should be no leak at all when the array is released during app shutdown 
or assigned nil.  For a running app the leak gets worse and worse.  I assume 
that assigning nil to the ISuperArray interface variable should destroy the 
array and it's contents.  Are the users responsible for releasing the elements 
manually??

What version of the product are you using? On what operating system?
Delphi XE2, 32bit mode, Latest X-SuperObject from source repo as of 2015-01-07.

Please provide any additional information below.
I noticed this in my much more complex app.  Was running out of memory 
eventually.

Original issue reported on code.google.com by MarkRadf...@gmail.com on 7 Jan 2015 at 6:22

Attachments:

GoogleCodeExporter commented 9 years ago
Additional note.  Simple elements in SuperArray do not cause memory leak.

Original comment by MarkRadf...@gmail.com on 7 Jan 2015 at 6:24

GoogleCodeExporter commented 9 years ago
Found the solution.  The ISuperArray interface was missing the two Add methods 
for ISuperArray and ISuperObject.  Adding them to the interface solved the 
memory issues.  Must have been calling one of the other overloaded Add methods 
(variant, JSONAncestor, etc.) which leaked the memory.  Discovered this by 
creating array directly from JSON text which DID NOT leak.

on ISuperArray interface add the following two to match the TSuperArray class:
    procedure Add(Value: ISuperObject); overload;
    procedure Add(Value: ISuperArray); overload;

Original comment by MarkRadf...@gmail.com on 8 Jan 2015 at 8:41

GoogleCodeExporter commented 9 years ago
Thanks for the info Mark.. this may be the cause of some memory leaks i am 
seeing in my app too...

Original comment by geraldsa...@gmail.com on 24 Feb 2015 at 5:11

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r89.

Original comment by onryld...@gmail.com on 10 Mar 2015 at 10:20