Dereference TRef-s read from TFile after closing the file

Dear ROOT Experts,

I am working on a project based on ROOT and using TRef-s to maintain pointers through file storage. When reading objects from a ROOT file to memory which contain TRef-s to other objects (also read from the same file), I would like to be able to dereference the TRef-s regardless of whether the TFile from which everything was read is still open. Is it possible to still use the TRef-s if the original file was closed?

Please find a small example demonstrating my problem below.
If the whole code is run, the test.root file is created and when it is read during execution of the same program, the TRef B can be properly dereferenced even though the file from it was read is already closed.

Now if the section which produces the file is commented out (see marking comments) and the program is run again to only read the previously-created file, closing the file makes the TRef stop pointing to object A (B->GetObject() returns NULL).

I guess the fact that the TRef works after closing the file in the first case has something to do with the TRef being assigned earlier in the same process but my understanding of how TRef works internally it too poor to find a solution for the second case.
Is it possible to read the objects and TRefs from file, close the file, and still have the TRef-s working?

[code]#include
#include
#include “TNamed.h”
#include “TRef.h”
#include “TFile.h”
#include “TProcessID.h”

int main(){

// producing the file - comment out from HERE
{
TFile file(“test.root”, “RECREATE”);
TNamed * A = new TNamed(“A”, “Object A”);
TRef B;
B = A; // assign the TRef
file.WriteObject( A , “A”);
file.WriteObject( &B , “B” );
file.Close();
delete A;
}
// to HERE

// reading the file
TFile file(“test.root”, “READ”);
TNamed * A = (TNamed*)file.Get(“A”);
TRef * B = (TRef*)file.Get(“B”);

file.Close(); // from now on the TFile is closed

TNamed * A_referenced = (TNamed*)(B->GetObject()); // dereference the TRef

if( A_referenced ){
std::cout<<A_referenced->GetTitle()<<std::endl;
}else{
std::cout<<“A_referenced is NULL”<<std::endl;
}
}
[/code]

Thank you in advance!
Alek