# How to delete RDataFrame and clean up memory

**URL:** <https://root-forum.cern.ch/t/how-to-delete-rdataframe-and-clean-up-memory/33036>\
**Category:** ROOT\
**Tags:** rdataframe, python, tree, root\
**Created:** [March 5, 2019, 7:06pm UTC](https://root-forum.cern.ch/t/how-to-delete-rdataframe-and-clean-up-memory/33036 "2019-03-05T19:06:01Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![Daniil\_Ponomarenko](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/daniil_ponomarenko/32/18136_2.png) [@Daniil\_Ponomarenko](https://root-forum.cern.ch/u/Daniil_Ponomarenko)\
**Post date:** [March 8, 2019, 10:17pm UTC](https://root-forum.cern.ch/t/how-to-delete-rdataframe-and-clean-up-memory/33036/7 "2019-03-08T22:17:53Z")

</div>

Good day,

here is simple example that make RAM usage really explode:

```auto
import ROOT
import os
import time

@profile
def loopDataFrame(treeName, file, cuts):
	print "Processing %s"%file
	print "Processing %s"%cuts
	df = ROOT.ROOT.RDataFrame(treeName, file)
	for cutName, cutDef in cuts.iteritems():
		df = df.Filter(cutDef)
	model = ROOT.RDF.TH1DModel("lep_0_p4.Pt()", ";p_{T} (lep_{0}) GeV;", 100, 0., 100.)
	myHisto = df.Define("myP4", "lep_0_p4.Pt()").Histo1D(model, "myP4")
	return myHisto

@profile
def main():
	file = 'merged.root'
	treeName = 'NOMINAL'

	ROOT.ROOT.EnableImplicitMT()

	cuts = {}
	for i in range(0,100):
		cuts['lePt%s'%i] = 'lep_0_p4.Pt()>%s'%i
		hist = loopDataFrame( treeName, file, cuts )
		hist.Draw()
		time.sleep(1)

	raw_input("Press Enter to continue...")

if __name__ == ' __main__': main()
#EOF

```

Plots for only 10 iterations:

 ![Mem_CutOnly](https://root-forum.cern.ch/uploads/default/original/3X/d/7/d71a7c273542577015028549aed55a300b4394ba.png)

And other plot w/o calling `hist.Draw()`:

 ![Mem_CutOnly](https://root-forum.cern.ch/uploads/default/original/3X/a/e/ae0ebeea5ebe58f788504e9ff4a4d4d48d12c4b6.png)

Logs: [logs.txt](https://root-forum.cern.ch/uploads/default/original/3X/9/c/9ce98a2b48a27ec508786efd2589121468379fb8.txt) (3.5 KB)

Looks like @eguiraud first guess is the right one. If the script doesn’t create new jitters, there is no memory slope. However, this memory stays to be used even after the end of an executable function.  
That would be awesome to have some sort of `RDataFrame::Clean()` or `RDataFrame::Delete()` method to clean up memory.

---

_[View the full topic](https://root-forum.cern.ch/t/how-to-delete-rdataframe-and-clean-up-memory/33036)._
