Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debug Assertion Failed: _CrtIsValidHeapPointer(block)

I wrote a code that simulates a matrix. this matrix has a pointer to pointer and actually its an array of linked list. i have two of those - one for the rows and the second for the column. each array index its the matrix row/col first place, and the list is the rest number in the rox/col.

I can send the code, but its not short.

My problem is that after im doing some actions, and im trying to delete the matrix at the end - it pop me this Failed problem. I have tryed to change my code and I found that the problem is here:

delete this->rowsArray;
this->rowsArray = newRowArray; ->here


delete this->colsArray;
this->colsArray = newColArray; ->here

rowsArray ad colsArray initilized like that:

rowsArray = new matrixNode*[lastRowPlace+1]; colsArray = new matrixNode*[lastColPlace+1];

same about newColsArray and row... I hope you would be able to give me an advice cause I really dont know what to do :(

**Just forgot to say that the problem pop just at the destructor...

like image 723
Ben Avatar asked Nov 08 '25 03:11

Ben


1 Answers

If you defined a pointer such as new T* [size]

you should delete it with delete[] instead of delete

like image 185
永东何 Avatar answered Nov 10 '25 17:11

永东何



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!