• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 165
  • Last Modified:

problem with delete

hi guys,

i don't know what this error comes from.
i have created some object with new. Lets say 10 and now when i start deleting them their is a very strage thing.
when i delete the 3th object the 7th gets deleted too. And then when i want to delete the 7th i get an exeption because it's
allready gone.
If anybody knows what it is please help me.
  • 2
1 Solution
See the identification of the object.
Case if it is an array see if it doesn't have the same index.
have you copied 3rd object to 7th, or 7th to 3rd, or have you created them similar way like you tried to put same data into them from some other objects or variables..
I mean maybe you shallow copied two objects, like some part of them is pointing to the same thing, so when you delete one of them, that "thing" they both are pointing to gets deleted, and when you are trying to delete second, it is not there anymore, that's why you are getting error
kkmilanAuthor Commented:
no i didn't copied the object. But i've found my mistake.
The object has a pointer to itselfs structure and the 3th element points to the 7th element. Now when i delete the 3th objects it deletes the 7th too. The question now is how can i avoid deleting the 7th element when i still want the 3th element deleted.
thanks anyway for your anwers.
kkmilanAuthor Commented:
erm i've got another question. When i've got a program witch just creates 100000 pointer on an int. I store them in the std::list<int*>
when i have a look at the windows task manager it shows me the  memory-size my small program uses, right?!

ok now i delete every created int but the task manager seem not to decrese the memory-size. why is that?


Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now