Skip to content

[Root7] A path to reducing global memory management.#18083

Draft
hageboeck wants to merge 27 commits intoroot-project:masterfrom
hageboeck:root7-memoryManagement
Draft

[Root7] A path to reducing global memory management.#18083
hageboeck wants to merge 27 commits intoroot-project:masterfrom
hageboeck:root7-memoryManagement

Conversation

@hageboeck
Copy link
Member

@hageboeck hageboeck commented Mar 20, 2025

This is a longer-term effort to update ROOT to work both with implicit and explicit object ownership (i.e. whether THx and similar are owned by gDirectory). The branch started by switching off this ownership and fixing all failing tests. These fixes will be done in a way that the code works both with and without implicit ownership, and will be split off into other PRs to keep the review load manageable. Once that's done, the final names and implementations of the ownership-related functions will be decided here.

TODOs:

  • Add tests for implicit / explicits registration of TH1s
  • Extend the test coverage to other classes where implicit registration is altered.

Note: No need to review until the following PRs are merged:

Bool_t TH1::AddDirectoryStatus()
{
return fgAddDirectory;
return !ROOT::ROOT7MemoryManagement() && fgAddDirectory;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this flag is primarily about file constructions (and secondarily about shared ownership). Beside the (intentional) memory leak it introduces in existing scripts, it leads most of them to not longer write the histograms to the file (because they are no longer attached to the File). It is not clear whether this kind of approach is worth it compared to a more user active change (ie. Switching explicitly from TFile to RFile).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the information!
Details will be discussed on the ROOT retreat next week.

@github-actions
Copy link

github-actions bot commented Mar 21, 2025

Test Results

    15 files      15 suites   2d 8h 20m 43s ⏱️
 3 768 tests  3 768 ✅ 0 💤 0 ❌
50 876 runs  50 876 ✅ 0 💤 0 ❌

Results for commit 8d9511a.

♻️ This comment has been updated with latest results.

@pcanal pcanal dismissed a stale review March 23, 2025 15:29

Please tell us why you approve this request.

@hageboeck hageboeck force-pushed the root7-memoryManagement branch from 4d29c60 to 1224a4b Compare September 5, 2025 15:50
@hageboeck hageboeck force-pushed the root7-memoryManagement branch from b894456 to 167c0cc Compare November 3, 2025 10:35
@hageboeck hageboeck added the clean build Ask CI to do non-incremental build on PR label Nov 3, 2025
@hageboeck hageboeck force-pushed the root7-memoryManagement branch from 342a3cb to 0ca4f8a Compare November 5, 2025 17:34
@hageboeck hageboeck force-pushed the root7-memoryManagement branch from 0ca4f8a to 68de9c4 Compare January 14, 2026 13:23
@hageboeck hageboeck force-pushed the root7-memoryManagement branch from 68de9c4 to 9c5ce87 Compare January 21, 2026 12:53
@hageboeck hageboeck force-pushed the root7-memoryManagement branch from 9c5ce87 to b79032e Compare February 10, 2026 17:35
When calling TDirectory::Append(obj, replace=true), and obj is already
in the directory, don't issue a warning. Proceed to clear the list of any
duplicates, issuing a warning for each.

This will enable workflows such as:
   auto h = new TH1D(...);
   directory->Append(h, true);

After this change, the above lines work both with implicit object
ownership off and on.
This makes TEfficiency consistent with other histogram-like classes, in
the sense that it only adds itself to a directory if the corresponding
flags are on.
- Don't rely on implicit registration to directories.
- Make the test insensitive to any defaults by always adding the
  histogram to the file.
When histograms get added to a THStack, they are likely in multiple
TLists. Therefore, the kMustCleanup bit must be set.
In the past, the bit usually got set automatically when histograms added
themselves to directories, but when this is disabled, the cleanup bit
remained unset.
The function documentation explicitly states that the histograms created
by these operations are added to the current directory, so this is done
explicitly here.
This makes the code independent of whether implicit ownership is on or
off.
Explicitly assign histograms to directories. In this way, the tests
proceed irrespective of whether or not implicit object ownership is in
use.
The test was relying on implicit ownership to transfer a histogram from
python to C++, so now the histogram is appended explicitly.
When implicit histogram ownership is off, the co-ownership of a function
both by the global list of functions and by a histogram lead to a double
delete.
The tutorial was running code that didn't directly reference the
histogram, so it failed when implicit ownership is off.
- Add DisableImplicitObjectOwnership() and
  EnableImplicitObjectOwnership().
- Add a function to test if ownership is on or off.
- Add a silentOff mode for running tests that check the program output.
- Allow for setting defaults using
  - The environment variable ROOT_IMPLICIT_OWNERSHIP
  - The rootrc variable Root.ImplicitOwnership
…ived.

- Couple TH1::AddDirectoryStatus to
  ROOT::DisableImplicitObjectOwnership.
- Add a manual exception for TTree::Draw(): Histograms and profiles will
  still register themselves to gDirectory because the registration is an
  essential part of the feature.
@hageboeck hageboeck force-pushed the root7-memoryManagement branch from b79032e to 74a6279 Compare February 12, 2026 16:38
@hageboeck hageboeck force-pushed the root7-memoryManagement branch from 74a6279 to 8d9511a Compare February 12, 2026 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clean build Ask CI to do non-incremental build on PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants