Hm, what’s wrong with this code?
[code]#define DEBUG
#include “TObjArray.h”
#include “TObjString.h”
#include “mex.h”
#include “mpatrol.h”
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
#if defined(DEBUG)
__mp_startleaktable();
#endif
TObjArray *array = new TObjArray();
TObjArray *cell = new TObjArray();
array->SetOwner();
cell->SetOwner();
TObjString *str1 = new TObjString("test1");
TObjString *str2 = new TObjString("test2");
TObjString *str3 = new TObjString("test3");
cell->Add(str2);
cell->Add(str3);
array->Add(str1);
array->Add(cell);
delete array;
#if defined(DEBUG)
__mp_stopleaktable();
__mp_leaktable(0, MP_LT_ALLOCATED, MP_LT_BOTTOM);
__mp_leaktable(0, MP_LT_FREED, MP_LT_BOTTOM);
__mp_leaktable(0, MP_LT_UNFREED, MP_LT_BOTTOM);
#endif
}
[/code]
mpatrol prints this leak table:
[code]bottom 5 allocated memory entries in leak table:
bytes count location
-------- ------ --------
20 1 test.cpp line 21
20 1 test.cpp line 22
20 1 test.cpp line 23
40 1 test.cpp line 15
40 1 test.cpp line 16
140 5 total
bottom 1 freed memory entry in leak table:
bytes count location
-------- ------ --------
40 1 test.cpp line 15
40 1 total
bottom 4 unfreed memory entries in leak table:
bytes count location
-------- ------ --------
20 1 test.cpp line 21
20 1 test.cpp line 22
20 1 test.cpp line 23
40 1 test.cpp line 16
100 4 total[/code]
Does this SetOwner trick work in nested collections?
Do I have to invoke the garbage collection by hand?
Does ROOT typically make garbage collection or just recursively call the destructors? Both methods seem to be implemented. What should I use?
[color=red]Edit:[/color]
I link only these libs: -lCore -lCint -lRIO -lXMLIO -lNet -lSQL -lRootAuth -lMathCore -lMatrix