Hi Alberto,
you'll need to remove the objects from all collections containing it
when deleting the object. The reason is the same as here:
MyObj* a=new MyObj();
MyObj* b=a;
delete a;
Now, b is pointing to an invalidated place in memory - nobody told b that the object it was pointing to has been deleted, and it's impossible for b to find out. So
TObjArray oa1; TObjArray oa2; TObjArray oa3;
oa1.Add(a); oa2.Add(a); oa3.Add(a);
oa1.Remove(a); oa2.Remove(a); oa3.Remove(a);
or
...
oa1.Remove(a); oa2.Remove(a); oa3.Delete(a);
should work.
Axel.
Alberto Pulvirenti wrote:
> Dear rooters,
>
> I am encountering a strange problem when creating collection of objects
> which I defined, that I collect in many collection objects of ROOT.
> What happens is that I need tro put the same element in different
> collections. But, when I call the Delete() method in the first, it seems
> that something is not deleted in the second, and then I get segmentation
> faults when using the iterator in that collection, because if "finds"
> object that should be deleted.
>
> I don't know how to solve this problem.
>
> Cheers,
> Alberto
>
Received on Fri Mar 04 2005 - 20:11:05 MET
This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:05 MET