Macro crashes when closing the file after saving the trees with 'double free or corruption (out)' message

I am trying to fill a tree with branches with user-defined class-objects. When I am finished writing the file with the tree as in ‘t_cands->Write()’, save the file as ‘outfile ->Save();’ and then close the file as ‘outfile ->Close();’, I get the following error and the macro crashes:

double free or corruption (out)

I don’t understand the meaning of the error or the cause. It happens just when I try to close the file in the macro.

Any help in identifying the error would be much appreciated as I am new to root.

ROOT Version: 6.28/06
Platform: macOS Sonomo 14.0
Compiler: clang-1500.0.40.1

What is the stack trace of the error? Do you delete the tree or histograms after the call the Close (which actually should be better to be a class to delete outfile

Hi @pcanal,
Thanks for helping out.
I delete the file as you pointed out. delete outfile
This is all the message I get before the macro crashes out of root. No stack trace as such