{ gROOT->Reset(); // create an object arry on stack TObjArray a; TObjString str1("StackString1"); TObjString str2("StackString2"); // add some heap strings owned by obj array a.Add(new TObjString("Energy")); a.Add(new TObjString("Peak")); a.Add(&str1); a.Add(&str2); // print all a.Print(); TString tmp; // loop over list an print the strings for(int i=0; i<=a.GetLast(); i++){ // get ClassName of each element tmp = a[i].ClassName(); cout << i<< " : " << tmp.Data() << ": " ; // check if on heap or stack if(a[i].IsOnHeap()) cout << " On Heap: "; else cout << "On Stack: "; if(tmp == TString("TObjString")) cout << ((TObjString*)a[i])->String().Data() ; cout << endl; } //IO TFile f("TObjArrayTest.root","RECREATE"); a.Write("a",TObject::kSingleKey); f.ls(); f.Close(); //cleanup a.Delete(); // delete all Objects recursively - causes crashes if run twice in cint // does not work either: cout << "IsZombie = " << a.IsZombie() << endl << endl; }