# Potential Memory leak?

**URL:** <https://root-forum.cern.ch/t/potential-memory-leak/52180>\
**Category:** Newbie\
**Tags:** hist, root\
**Created:** [November 1, 2022, 12:29am UTC](https://root-forum.cern.ch/t/potential-memory-leak/52180 "2022-11-01T00:29:01Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [November 1, 2022, 7:24am UTC](https://root-forum.cern.ch/t/potential-memory-leak/52180/2 "2022-11-01T07:24:02Z")

</div>

You need:

```cpp
   // ...
   TH1D *h = new TH1D("Energy", "Final Energy; Protons; Frequency", 50, 0., 2.);
   for (Long64_t jentry = 0; jentry < nentries; jentry++) {
   // ...
		      if (pdgf[pdgindex] == 2212) {
		      	  h->Fill(Your_Particle_Final_Energy_Value); // maybe (Ef[pdgindex])
		      }
   // ...
   }
   h->Draw();
   // ...

```

BTW. If this is the same tree as in the [“InteractionsII.root”](https://root-forum.cern.ch/t/creating-a-histogram-of-particle-final-energies-using-their-pdg-codes/52121) file, instead of:  
` for (Long64_t pdgindex=0; pdgindex<28;pdgindex++)`  
you need:  
` for (Int_t pdgindex = 0; pdgindex < nf; pdgindex++) // if you use the "pdgf[nf]/I " branch inside`  
or:  
` for (Int_t pdgindex = 0; pdgindex < ni; pdgindex++) // if you use the "pdgi[ni]/I " branch inside`

---

_[View the full topic](https://root-forum.cern.ch/t/potential-memory-leak/52180)._
