# Will a pointer contents been deleted after TTree::Fill()?

**URL:** <https://root-forum.cern.ch/t/will-a-pointer-contents-been-deleted-after-ttree-fill/60142>\
**Category:** Newbie\
**Tags:** root\
**Created:** [July 9, 2024, 12:15pm UTC](https://root-forum.cern.ch/t/will-a-pointer-contents-been-deleted-after-ttree-fill/60142 "2024-07-09T12:15:05Z")\
**Posts on this page:** 2\
**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:** [July 9, 2024, 12:15pm UTC](https://root-forum.cern.ch/t/will-a-pointer-contents-been-deleted-after-ttree-fill/60142/1 "2024-07-09T12:15:05Z")

</div>

Dear experts

I have a customized class that will been filled to a `TTree`, I wonder do I need to call `delete objectA; objectA = nullptr;` after every `Fill()`?

---

<div class="post-metadata">

**Author:** ![jonas](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jonas/32/24756_2.png) [@jonas](https://root-forum.cern.ch/u/jonas)\
**Post date:** [July 9, 2024, 10:12pm UTC](https://root-forum.cern.ch/t/will-a-pointer-contents-been-deleted-after-ttree-fill/60142/2 "2024-07-09T22:12:27Z")

</div>

Hi @Crisps!

No, you should not call `delete` after every fill.

See the documentation ([ROOT: TTree Class Reference](https://root.cern.ch/doc/master/classTTree.html#addingacolumnofobjs)):

> The object must not be destroyed (i.e. be deleted) until the [TTree](https://root.cern.ch/doc/master/classTTree.html) is deleted or [TTree::ResetBranchAddress](https://root.cern.ch/doc/master/classTTree.html#a181eb19c03433781fde2fa94443710dc) is called.

You’re creating the object once on the beginning, like here in this tutorial:  
[https://root.cern/doc/master/tree4\_8C.html](https://root.cern/doc/master/tree4_8C.html)

Here, the object is this:

```c++
  // Create a pointer to an Event object
  Event *event = new Event();

```

Note that this tutorial has a memory leak because `event` is never deleted (according to the docs I linked before, it should be kept alive until the TTree is destructed).

I hope this helps!  
Jonas
