TClonesArray not owner?

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… :cry:
==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)

Laurent,

I suggest to have a look at TClonesArray::RemoveAt
root.cern.ch/root/htmldoc/src/TC … y:RemoveAt

Rene

Hi Rene,

Sorry for the late reaction.

Indeed I’ve had a look at the RemoveAt method, and that’s why I was trying to set ca[i] to 0 (judging that in this case RemoveAt would not try to delete my pointer at i). But it seems that ca[i]=0 itself is quite an invalid thing to do (as stated in TClonesArray::operator[], which I’ve first overlooked).

So I guess I will have to think a bit more about how to solve my problem…

Anyway, thanks for the answer,

Regards,