Open karuboniru opened 1 month ago
Hi,
Could you explain why the classes are forced not to be selected without the "+", which brings many benefits, among which performance during the IO procedures?
In the case for GENIE neutrino generator, its a software with a long history, I am unable to trace back to the time when the LinkDef.h
was written.
And it seems that adding the plus sign will break some compatibility with root files generated without the plus sign, so that's not going to be easy.
We are no longer updating the old I/O (the one you get without the +
) as its test suite is minimal and we have no idea what users still using are relying on.
However you can straightforwardly migrate to the new I/O and solve the problem for you classes.
The result of the process applied to your example can be seen in the merge request against your example: https://github.com/karuboniru/root_memory_leak_report/pull/1
This was created (beside the small tidying commits) by:
+
.-
to the LinDef: karuboniru/root_memory_leak_report@f454e98
(#1)After this steps, there is no change in behavior yet.
This accomplish in karuboniru/root_memory_leak_report@37d09c9
(#1)?diff=split
After this step the new code will write and read new file without a memory lead. It will be able to read the old file with the same memory as before.
This is seen in karuboniru/root_memory_leak_report@8c6bb1d
(#1)
After this we have:
Check duplicate issues.
Description
If a class allocates memory in its ctor (and deallocates in dtor). And included in
LinkDef.h
without+
after class name. During I/O, the ctor will be called but not the dtor.Reproducer
Please refer to this code: https://github.com/karuboniru/root_memory_leak_report
It compiles to
gen
,read{,_old}
.gen
produces a.root
file containing a tree of user defined classTestData
. Andread
read_old
read the tree to do something.read
uses RDataFrame language andread_old
uses oldSetBranchAddress
way.In the constructor of TestData, it will allocate memory for class
a_member
. And deallocate it in its destructor. Any call to the constructor or destructor of classa_member
will be logged.If
#pragma link C++ class TestData;
, instead of#pragma link C++ class TestData+;
is in theLinkDef.h
, the read program will contain multiple call toa_member::a_member
but only single or none call toa_member::~a_member
, potenially causing memory leak per entry processed.ROOT version
Installation method
reproducable from self build (from copr), from fedora repo (official version) and ROOT from
/cvmfs/sft.cern.ch/lcg/views/LCG_106/x86_64-el9-gcc13-opt/setup.sh
Operating system
Linux Fedora 41 and CentOS9
Additional context
This issue seems to be causing massive memory leak with GENIE. The GENIE related tools manually cleans the resources but it seems I can't do the same with RDataFrame.