It's a pretty sure thing that you're looking at the effect rather than the cause.
Something else is probably trashing memory. Here is just where you first notice there is a problem.
In a correct program, there is no apparent difference between debug and release (except speed). That you are observing a difference is a sure sign of bugs.
It depends on how large the program is as to what to do about it.
One thing to do is examine carefully all your other classes. Especially any where you call new/delete explicitly.
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
Memory can be trashed in many ways.
Running off the end of the array
int length = 10;
int *p = new int[length];
for ( int i = 0 ; i <= length ; i++ ) p[i] = 0;
<= should be <Freeing the same memory twice
int *p = new int [10];
delete [] p;
// more code
delete [] p; // oops
Freeing what wasn't allocated
int *p = new int [10];
// code
p++; // say walking the array
delete [] p; // oops, this isn't what new returned
Edit:
I wrote this, then saw your fix, so I posted it anyway.
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953