# Should I release memory of a TBranch member

**URL:** <https://root-forum.cern.ch/t/should-i-release-memory-of-a-tbranch-member/62287>\
**Category:** Newbie\
**Tags:** root\
**Created:** [November 21, 2024, 7:26am UTC](https://root-forum.cern.ch/t/should-i-release-memory-of-a-tbranch-member/62287 "2024-11-21T07:26:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Crisps](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/crisps/32/39101_2.png) [@Crisps](https://root-forum.cern.ch/u/Crisps)\
**Post date:** [November 21, 2024, 7:26am UTC](https://root-forum.cern.ch/t/should-i-release-memory-of-a-tbranch-member/62287/1 "2024-11-21T07:26:18Z")

</div>

Dear experts

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

```auto
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…?

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [November 21, 2024, 3:46pm UTC](https://root-forum.cern.ch/t/should-i-release-memory-of-a-tbranch-member/62287/2 "2024-11-21T15:46:15Z")

</div>

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](https://root.cern/doc/master/classROOT_1_1RDataFrame.html):

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

```

Cheers,  
D

---

<div class="post-metadata">

**Author:** ![Crisps](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/crisps/32/39101_2.png) [@Crisps](https://root-forum.cern.ch/u/Crisps)\
**Post date:** [November 22, 2024, 2:26am UTC](https://root-forum.cern.ch/t/should-i-release-memory-of-a-tbranch-member/62287/3 "2024-11-22T02:26:57Z")

</div>

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…

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

```

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

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [November 22, 2024, 4:41am UTC](https://root-forum.cern.ch/t/should-i-release-memory-of-a-tbranch-member/62287/4 "2024-11-22T04:41:19Z")

</div>

Hi,

RDF is present in 6.18, as well as the `Take` action: [ROOT: ROOT::RDF::RInterface\< Proxied, DataSource \> Class Template Reference](https://root.cern/doc/v618/classROOT_1_1RDF_1_1RInterface.html#aa571f08b8e4d9300cacdea039a379a22)

In order to copy the values, you can do

```auto
b.push_back(*a);

```

Best,  
D

---

<div class="post-metadata">

**Author:** ![Crisps](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/crisps/32/39101_2.png) [@Crisps](https://root-forum.cern.ch/u/Crisps)\
**Post date:** [November 22, 2024, 5:01am UTC](https://root-forum.cern.ch/t/should-i-release-memory-of-a-tbranch-member/62287/5 "2024-11-22T05:01:32Z")

</div>

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