Hi,
Sorry for the generic (and maybe stupid) question… Is there a way to make a TClonesArray which is not owner of (some of) its objects ? (From what I’ve read in the doc, it’s not really possible, but who knows how well I understood the doc ?)
The idea is that I do have somewhere a (stl) vector holding some smart pointers to the objects of the TClonesArray (that I really need for I/O purposes). I do not want the TClonesArray dtor to delete objects that are still referenced somewhere else. I’ve tried to play with SetOwner with no success. What I’m doing now is just to set the pointer to the object to 0 before deleting the TClonesArray, e.g.
TClonesArray* ca = …
for ( int i = 0; i < ca->GetLast()+1; ++i )
{
if ( notownerof(i) ) // this tells me if someone else keep a reference to that ptr
{
(*ca)[i] = 0;
}
}
delete ca;
At first sight it seemed to work, but valgrind has another opinion on that…
==14481== Address 0x4854F860 is 0 bytes inside a block of size 80 free’d
==14481== at 0x4002BDD0: __builtin_delete (vg_replace_malloc.c:233)
==14481== by 0x40372518: TStorage::ObjectDealloc(void *) (in /opt/cern/root/root_v3.05.07/lib/libCore.so)
==14481== by 0x4035D1F7: TObject::operator delete(void *) (in /opt/cern/root/root_v3.05.07/lib/libCore.so)
…
Any hints would be most appreciated,
Best regards,
PS: I’m using ROOT 3.05/07 on RH7.2 (gcc 2.95.3)