Reputation: 916
I have a nasty bug in my C++ project. There's a class
class SomeClass {
...
std::string *someString;
...
}
Here's a constructor
SomeClass(...) {
...
someString = new std::string("");
...
}
And the thing is that afterwards I operate only with that specific string, without modifying the poiner value. I assign to that string different strings all the time, like
*someString = "whatever";
someString->assign("whatever");
*someString += 'a';
Application is multithreaded and there's a really nasty glitch. At some point, application crashes. Debugger shows that variable someString has A BAD POINTER. And I have no idea how this is possible
delete someString;
IS NEVER CALLED.
I've looked to all the references of that string pointer and here's what I can tell you:
Therefore, I need to find a way to check when a destructor is called on a specific object. In fact, array of objects.
So, is there a way to set a breakpoint on a destructor (or any other method) on a specific set of objects (I'm working on visual studio 2010 proffessional)?
Upvotes: 0
Views: 745
Reputation: 35388
If you are multithreading, consider implementing a locking mechanism ... (if you didn't do it already) for your string member. Highly possible one thread tries to write to a pointer which is being reallocated in a different thread... or something like this. A little bit more code would help us to understand the problem in a deeper context.
Upvotes: 1