Skip to content

Disable unused event branches to prevent memory leak#564

Open
cmargalejo wants to merge 4 commits intomasterfrom
cris_fix_event_branch_memory_leak
Open

Disable unused event branches to prevent memory leak#564
cmargalejo wants to merge 4 commits intomasterfrom
cris_fix_event_branch_memory_leak

Conversation

@cmargalejo
Copy link
Copy Markdown
Member

@cmargalejo cmargalejo commented Apr 20, 2026

cmargalejo Ok: 3 Powered by Pull Request Badge

Investigation started from rest-for-physics/detectorlib#124, where @AlvaroEzq reported the leak from #542 was still present after the destructor fix.

When a REST file stores multiple event types (e.g. Raw → Signal → Hits → Track), only the last one is actually used. But all event branches in the tree were left enabled. Each time GetEntry() reads the tree, ROOT creates internal objects for the unused branches that never get freed. This causes memory to grow. The fix consists on, after opening the file, disabling all event branches except the one being used.

Fixes #542 (hopefully...)

@cmargalejo cmargalejo requested a review from AlvaroEzq April 20, 2026 13:58
@cmargalejo cmargalejo requested a review from nkx111 as a code owner April 20, 2026 13:58
@AlvaroEzq
Copy link
Copy Markdown
Contributor

Fixes #542 (hopefully...)

Yes! I tested these changes and they avoid the memory leak of #542.

When a REST file stores multiple event types (e.g. Raw → Signal → Hits → Track), only the last one is actually used.

But I am concerned this is not true. I use multiple event types stored in the same REST file and all of them can be used. For instance, the REST_ViewEvents.C macro can be used to visualize the different event types of the same event if they are stored in the same REST file. I tried doing exactly this and now it crashes 😢 :.

I think we should try to preserve this feature of storing multiple event types for both functionality and retrocompatibility. If we found it is not possible, then discuss which way to go.

@cmargalejo
Copy link
Copy Markdown
Member Author

cmargalejo commented Apr 21, 2026

I have pushed a fix so that switching between event types in REST_ViewEvents works again with Raw, Hits and Track events.

However, switching to a TRestDetectorSignalEvent still crashes... I think it's a separate bug in that class. I'll open an issue. Its in rest-for-physics/detector#125 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Memory leak when opening files made with REST<latest (?)

2 participants