Disable TTree saving into TFile

Dear all.
I’d like to create and use a TTree in a ROOT based application, but I do not want to have it saved into my output file… It is just a tree that I use in my App to perform analysis studies but I do not need it to be saved. I create it using the new TTree() constructor and I tried to explictly Delete() it from my output TFile before closing it and writing it… But I see that while the tree is not there (in the output file) its memory is still used… :frowning: So: there’s no TTree when I call the gDirectory->ls() in my output file, but the file size tells me (since it is so big) that the TTree is still occupying space :frowning:( …
How can I get rid of this unwanted memory allocation? I do not want to have the tuple saved in my file!!!


Many ROOT objects are automatically added to the current directory which is often just the root of the currently open TFile. Call SetDirectory(0) of your TTree after creating it to disable this autoadding. This works with many other types of ROOT objects as well.

Another simple solution … create AND fill your TTree before you open the ROOT file (it will belong to “gROOT” then).