For Programmers: Free Programming Magazines  


Home > Archive > VC STL > March 2005 > auto delete of objects in std::list<T>









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author auto delete of objects in std::list<T>
Corey Wirun

2005-03-02, 9:00 pm

(Excuse me if this appears twice. I posted and the server deleted it right
away for some reason).

Yet another question to y'all:

If I'm adding heap objects to a std::list<T> (created on the heap): e.g:

for (int i = 0; i < 10; i++)
{
TObject * p = new TObject();
pColl->push_back(p);
}

I noticed that the list destructor appears to 'delete' the TObject pointers
when the std::list<T> itself is 'delete'd. In xmemory, I see executing:

void deallocate(pointer _Ptr, size_type)
{ // deallocate object at _Ptr, ignore size
operator delete(_Ptr);
}

Sure enough, _Ptr, is an instantiation of my TObject object.

Can this behavior be conditionally modified? I have a situation where a
std::list contains a copy of some (not all) ptr's from a master std::list
and I don't want to 'delete' these objects since it would blow away the
master list contents as well.

Thanks for all your help! You guys are great!
Corey.


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com