Specific Memory Leak question

Started by
11 comments, last by Evil Steve 15 years, 7 months ago
Quote:Original post by Gazoo
Well by dereferencing the iterator I am deleting the object it is pointing to and not the actual iterator, but you do have a point as iterators are often invalidated when deleting things from the container they reference. I'll have a look at it... :)
What you're doing there is fine, the other poster was mistaken. You are just dereferencing the iterator to get the pointer to send to delete. It's okay for the container to then hold the memory address of a deleted block of memory, so long as you don't try to access it or delete it again. I would definitely put the .clear() immediately after that loop though, as you have done.
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms
Advertisement
From the code you have posted, I can't tell what the problem is. Perhaps you should try to create a tiny program that shows the problem, so we can look at the whole thing and try to reproduce the problem ourselves.

Unless you tried to have a container of objects and found that to be a performance bottleneck, I would say using a container of pointers is premature optimization.
There's nothing wrong in the code you've posted, I suspect the problem is in your updateTagPointsUnsorted() function.

This topic is closed to new replies.

Advertisement