Quote:Original post by GazooWhat 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.
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... :)
Specific Memory Leak question
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.
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
Popular Topics
Advertisement