How to decrease size of TFile?

Dear Rooters

I have created a TFile with two TDirectories, one containing 4 trees the other 3 trees.
On my Mac, this file has a size of 648 kB.
Then I deleted one directory and its 3 trees. Although the trees and directory are
deleted the file has still a size of 648 kB.

Is there a way to reduce the file size so that it uses less space on my harddisk?

Here are the maps of TFile before and after deletion of trees:

root [3] f.Map()
20050717/214541  At:100  N=274       TFile         
20050717/214541  At:374  N=115       TDirectory    
20050717/214542  At:489  N=21970     TBasket        CX =  2.91
20050717/214542  At:22459  N=19351     TBasket        CX =  3.31
20050717/214542  At:41810  N=51332     TTree          CX =  6.27
20050717/214542  At:93142  N=22458     TBasket        CX =  2.85
20050717/214543  At:115600  N=20491     TBasket        CX =  3.12
20050717/214543  At:136091  N=50944     TTree          CX =  6.32
20050717/215602  At:187035  N=6629      StreamerInfo   CX =  3.55
20050717/215602  At:193664  N=261       TDirectory    
20050718/215425  At:193925  N=135       FreeSegments  
Address = 194060        Nbytes = -161   =====G A P===========
20050717/214655  At:194221  N=117       TDirectory    
20050718/215425  At:194338  N=248       KeysList      
Address = 194586        Nbytes = -171   =====G A P===========
20050717/214600  At:194757  N=22052     TBasket        CX =  2.90
20050717/214600  At:216809  N=20212     TBasket        CX =  3.17
20050717/214600  At:237021  N=50858     TTree          CX =  6.33
20050717/214601  At:287879  N=21910     TBasket        CX =  2.92
20050717/214601  At:309789  N=20117     TBasket        CX =  3.18
20050717/214601  At:329906  N=51591     TTree          CX =  6.24
20050717/215602  At:381497  N=212       TDirectory    
Address = 381709        Nbytes = -391   =====G A P===========
20050717/214656  At:382100  N=21970     TBasket        CX =  2.91
20050717/214656  At:404070  N=19351     TBasket        CX =  3.31
20050717/214656  At:423421  N=51335     TTree          CX =  6.27
20050717/214657  At:474756  N=22052     TBasket        CX =  2.90
20050717/214657  At:496808  N=20212     TBasket        CX =  3.17
20050717/214657  At:517020  N=50862     TTree          CX =  6.33
20050717/214657  At:567882  N=21910     TBasket        CX =  2.92
20050717/214657  At:589792  N=20117     TBasket        CX =  3.18
20050717/214658  At:609909  N=51594     TTree          CX =  6.24
Address = 661503        Nbytes = -727   =====G A P===========
20050718/215425  At:662230  N=727       XFolder        CX =  2.58
20050718/215425  At:662957  N=1         END 
       

root [4] f1.Map()                            
20050717/214541  At:100  N=274       TFile         
20050717/214541  At:374  N=115       TDirectory    
20050717/214542  At:489  N=21970     TBasket        CX =  2.91
20050717/214542  At:22459  N=19351     TBasket        CX =  3.31
20050717/214542  At:41810  N=51332     TTree          CX =  6.27
20050717/214542  At:93142  N=22458     TBasket        CX =  2.85
20050717/214543  At:115600  N=20491     TBasket        CX =  3.12
20050717/214543  At:136091  N=50944     TTree          CX =  6.32
20050717/215602  At:187035  N=6629      StreamerInfo   CX =  3.55
20050717/215602  At:193664  N=261       TDirectory    
20050902/223845  At:193925  N=61        TDirectory    
20050902/223845  At:193986  N=148       FreeSegments  
Address = 194134        Nbytes = -10    =====G A P===========
20050902/223845  At:194144  N=194       KeysList      
Address = 194338        Nbytes = -419   =====G A P===========
20050717/214600  At:194757  N=22052     TBasket        CX =  2.90
20050717/214600  At:216809  N=20212     TBasket        CX =  3.17
20050717/214600  At:237021  N=50858     TTree          CX =  6.33
20050717/214601  At:287879  N=21910     TBasket        CX =  2.92
20050717/214601  At:309789  N=20117     TBasket        CX =  3.18
20050717/214601  At:329906  N=51591     TTree          CX =  6.24
Address = 381497        Nbytes = -603   =====G A P===========
20050717/214656  At:382100  N=21970     TBasket        CX =  2.91
20050717/214656  At:404070  N=19351     TBasket        CX =  3.31
20050902/223845  At:423421  N=655       XFolder        CX =  2.09
Address = 424076        Nbytes = -50680 =====G A P===========
20050717/214657  At:474756  N=22052     TBasket        CX =  2.90
20050717/214657  At:496808  N=20212     TBasket        CX =  3.17
Address = 517020        Nbytes = -50862 =====G A P===========
20050717/214657  At:567882  N=21910     TBasket        CX =  2.92
20050717/214657  At:589792  N=20117     TBasket        CX =  3.18
20050717/214657  At:609909  N=1         END           
root [5]

Best regards
Christian

This is a FAQ.
No it is not possible to decrease the size of a file. The gaps created by
the deletes will be used by the next Write/Fill.

Rene

Dear Rene

Thank you for your reply.
Sorrowly, this means that deleting 1GB from a file of 2GB will not free 1GB space on my HD.

P.S.: Since you mentioned that this is a FAQ, maybe it would be of help to have a FAQ section on the ROOT homepage?

Best regards
Christian

Christian,

We do not provide a garbage collector inside one file because it
is faster to create a new file. You can use the following trick:
-create an empty root file empty.root
-hadd newfile.root myfile.root empty.root

Note that the best FAQ is Google!

Rene

Dear Rene

Thank you for this tip, which works nicely unless you have your own classes also stored in the root file.
I assume that I need to copy these classes explicitely to the new file.

Google is surely the best way to search for answers, but is is no FAQ. In principle, the “HOWTO’s” section
can somehow be regarded as FAQ.

BTW, the bin directory contains hadd and some other binaries such as memprobe, olbd, rlibmap etc.
Sorrowly, I cannot find any documentation for these binaries. Maybe a description of these binaries could
be added to the user guide?

Best regards
Christian