Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > STL: delete needed along with erase?

Reply
Thread Tools

STL: delete needed along with erase?

 
 
AbrahamLincolnIllinois@yahoo.com
Guest
Posts: n/a
 
      07-09-2007
Hi all.

I have a list of pointers to a complicated object. When I erase() a
member of that list, the little blob of memory that contains the
pointer is deleted, I think. But the object pointed to is not
deleted, true? It is not an auto_ptr or any kind of wrapped
pointer.

Further, I assume that the iterator I am holding is no longer valid
once I delete the element. I can't safely erase the member first,
then delete the object through the iterator. So the sequence ought to
be: 1. Delete the object. 2. Erase the list element.

I am checking my understanding, because the code I am working on,
which I inherited, doesn't delete the object at all, either before or
after the element is erased.


Abraham

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      07-09-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> I have a list of pointers to a complicated object. When I erase() a
> member of that list, the little blob of memory that contains the
> pointer is deleted, I think.


Whatever the implementation does to get rid of it, yes.

> But the object pointed to is not
> deleted, true?


True.

> It is not an auto_ptr or any kind of wrapped
> pointer.


Right. You cannot use 'auto_ptr', but 'shared_ptr' should be fine.

> Further, I assume that the iterator I am holding is no longer valid
> once I delete the element.


You mean, once you *erase* it? "Delete" has a particular meaning in
C++, as you know. Yes, the iterator is invalid if you erase the list
element behind it.

> I can't safely erase the member first,
> then delete the object through the iterator. So the sequence ought to
> be: 1. Delete the object. 2. Erase the list element.


That sounds right.

> I am checking my understanding, because the code I am working on,
> which I inherited, doesn't delete the object at all, either before or
> after the element is erased.


Good thinking.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


 
Reply With Quote
 
 
 
 
AbrahamLincolnIllinois@yahoo.com
Guest
Posts: n/a
 
      07-09-2007
Thanks, Victor.

That's what I needed to know.


Abraham


On Jul 9, 9:22 am, "Victor Bazarov" <(E-Mail Removed)> wrote:
> (E-Mail Removed) wrote:
> > I have a list of pointers to a complicated object. When I erase() a
> > member of that list, the little blob of memory that contains the
> > pointer is deleted, I think.

>
> Whatever the implementation does to get rid of it, yes.
>


: :


 
Reply With Quote
 
Default User
Guest
Posts: n/a
 
      07-09-2007
(E-Mail Removed) wrote:

> Thanks, Victor.


Please don't top-post. Your replies belong following or interspersed
with properly trimmed quotes. See the majority of other posts in the
newsgroup, or the group FAQ list:
<http://www.parashift.com/c++-faq-lite/how-to-post.html>
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ping along a port ? barret bonden Cisco 3 05-25-2009 12:29 PM
OT:HNY Sing Along kpg MCSE 7 01-04-2006 05:32 PM
What is the extra bar along top in v1.5 with puzzle image? Can we get rid of? S.Rodgers Firefox 9 12-14-2005 11:15 AM
Can Firefox 1.5 be installed along side Firefox 1.0.6? Zygon Curry Firefox 6 09-14-2005 11:28 AM
Making objects move along with resizing browser page ? WJ ASP .Net 12 03-22-2005 12:16 PM



Advertisments