Got a couple questions. (this applies to C++)
I have a structure like this:
I am dynamically creating a array of Word pointers. That's the easier part.
Now that I'm done,I'm trying to minimize my memory leaks. Like a good coder does.
But now I'm like *arg* Kidding aside, I would like your guys advice on how to delete structures and dynamically allocated memory that those structures hold.
Here's what I've tried thus far:
Assume that the loop does not go out of bounds. (it doesn't I can assure it. It craps out on the first time it tried to delete.)
When it reaches the first delete in the for loop, I get a HEAP CORRUPTION DETECTED error in VS.
If I comment out the for loop and just do the last delete statement, it runs fine, but I still have lots and lots of memory leaks. This is essentially the only allocated memory that I do runtime. I just tried taking out all deletes and leaving the last one in: it results into 10 memory leaks each time.
What's up?
I have a structure like this:
Code:
struct Word
{
int count;
char* actualself;
};
I am dynamically creating a array of Word pointers. That's the easier part.
Now that I'm done,I'm trying to minimize my memory leaks. Like a good coder does.
But now I'm like *arg* Kidding aside, I would like your guys advice on how to delete structures and dynamically allocated memory that those structures hold.
Here's what I've tried thus far:
Code:
for (int i = 0; i < wordcount; i++) {
cout << "I " << i << endl;
delete [] wordarray[i].actualself;
}
delete [] wordarray;
Assume that the loop does not go out of bounds. (it doesn't I can assure it. It craps out on the first time it tried to delete.)
When it reaches the first delete in the for loop, I get a HEAP CORRUPTION DETECTED error in VS.
If I comment out the for loop and just do the last delete statement, it runs fine, but I still have lots and lots of memory leaks. This is essentially the only allocated memory that I do runtime. I just tried taking out all deletes and leaving the last one in: it results into 10 memory leaks each time.
What's up?