Disk space after TFile::Delete()

Dear Rooters,

I have a TFile with different TTrees.
If I delete a TTree {via file.Delete(“treename;*”)} the object disappears,
but the file size on disk does not change.
It seems that the free space is not released by TFile.

Is it possible to compact or re-zip the TFile to reduce its size after deleting objects?

Thank you

Marco

[quote]If I delete a TTree {via file.Delete(“treename;*”)} the object disappears,
but the file size on disk does not change.[/quote]This is the expected behavior.

[quote]It seems that the free space is not released by TFile.[/quote]The space can only be release if the freed blocks are at the end of the file. Any other recovery would involve moving data around in the file and thus are an expensive operation. Note that the freed block are available for further writing in the file.

[quote]Is it possible to compact or re-zip the TFile to reduce its size after deleting objects?[/quote]The best and most efficient way to do so is to copy the content of the file into a new file (for example by using TFileMerger or hadd).

Cheers,
Philippe.

Philippe,

not completely true. freed blocks may be reused when the file is closed and open again if the slot is large enough to accommodate a new record.

Rene

Reading the doc I think I should do as follows:

TFileMerger merg;
merg.AddFile(“original.root”);
merg.OutputFile(“output.root”);
merg.Merge();

My question now is: can be output=original so that the original file is overwritten?
Or I should create a temporary file, and move it via ::rename() to “original.root”?

Thank you

Marco

[quote]My question now is: can be output=original so that the original file is overwritten?[/quote]No.

[quote]Or I should create a temporary file, and move it via ::rename() to “original.root”?[/quote]Yes.

Otherwise the input file will be truncated before the data can be read out of it.

Cheers,
Philippe.