Should I release memory of a TBranch member

Dear experts

I want to read a std::vector<double> from a TTree so I do:

std::vector<double>* a;
std::vector<std::vector<double>> b;
t->SetBranchAddress("a", &a);
t->GetEntry(0);
b.push_back(std::move(*a));

should I do something to release the memory? Is the std::move() usage correct…?

Hi,

ROOT assumes that that memory can be used to read the branch for the events in the tree. If you want to accumulate the content of the branch, you should make a copy.
If I may suggest, you could use for that RDataFrame:

ROOT::RDataFrame rdf("myTree", "myFile.root");
auto b = rdf.Take<std::vector<double>>("a");

Cheers,
D

Thank you for your reply, this looks good, but I’m using a old version of ROOT on the server (ROOT v6.18), so I need to know how to use a old method to do it…

b.push_back(std::move(*a));

I think you mean this line is not correct and I should not use std::move()?

Hi,

RDF is present in 6.18, as well as the Take action: ROOT: ROOT::RDF::RInterface< Proxied, DataSource > Class Template Reference

In order to copy the values, you can do

b.push_back(*a);

Best,
D

Ah, that’s a good news for me! Thank you :blush: