Strange problem with a Destructor which crashes memory

Hi All,

I have a strange problem with my code! I have defined several 2D vectors in my function. It is a long function. In debugging mode, I found that there is a problem at the end of the function saying that:

"Exception thrown at 0x770CE43E (ntdll.dll) in hydroprime.exe: 0xC0000005: Access violation reading location 0x40719172."


Then I checked the destructors for the vectors and after counting the number of the destructors, found that the problem is because of a specific destructor.
I used the following command to make sure about that I am counting correctly:
1
2
3
4
5
6
7
8
vector<vector<double>> a(20, std::vector<double>(30));
vector<vector<double>> b(20, std::vector<double>(30));
vector<vector<double>> c(20, std::vector<double>(30));
 

vector<vector<double>>().swap(a);
vector<vector<double>>().swap(b);
vector<vector<double>>().swap(c);


Then I changed the location of the definition of the mentioned 2D vectors a and b and this time I got the error in b instead of a!!
It is something weird for me!

I spent around 5 days in this and could not solve this problem!! Appreciate if you share your thoughts!

Thanks.
Last edited on
if you could pinpoint your error, you would have fixed it already.
so don't go pasting snips that you think are relevant, post a minimal testcase that does reproduce your issue.

also, run your code through valgrind.
Last edited on
The problem is my code has hundreds of lines and around 200 classes! :|
The function also is really long!
From what little your code snippet shows why not just:
 
a.clear(); b.clear(); c.clear();

gunnerfunner: I tried both with the same result!
I'd take ne5555's advice here:
post a minimal testcase that does reproduce your issue.
It sounds like heap corruption earlier in your program. The problem with heap corruption is that the symptom (like the crash you're seeing) can appear long after the bug (the code that corrupts the heap).

Try running with a memory checker. What you use depends on the compilation environment that you have.
Topic archived. No new replies allowed.