Deleting a histogram pointer

Dear ROOTers,

I have an issue when deleting a histogram pointer when it is allocated to memory using new. Below are the relevant lines of code:

[code]TH1D *h = new TH1D(“h”, “h”, 32, 0, 32);

for (int l = 0; l < 32; l++){
h -> Fill(l);
}

OutFile -> cd();
h -> Write();
delete h;
[/code]

If I run the macro that this code is based off of, it will cause a segmentation fault. However, if I comment out the h-> Write() line there is no segmentation fault. Any thoughts as to why this would happen? I understand that it is good practice to delete every pointer that is allocated using new.

Hi,

I think you can find this post, and the doc it points to, suited for answering your question:

Cheers,
Danilo

Dear Danilo,

Thank you for your response. Can you recommend particular sections in the document that would be most focused on my question?

Hi,

timur already points out the most relevant in his post:

Hi,

Very good. Thank you for your response. I will be sure to read through the relevant sections.