How to delete CStatic object.
-
So you created a static like this:
mystatic = new CStatis;
, and deleted it like this:delete mystatis;
and you get something like "the heap around whatever has been corrupted"?> The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <
I have created member variable
CStatic *m_myStatic
;,I am allocating memory like thism_myStatic = new CStatic[m_filecount];,
and I am deleting in destructor.It is showing breakpoint is due to corruption of heap. -
I have created member variable
CStatic *m_myStatic
;,I am allocating memory like thism_myStatic = new CStatic[m_filecount];,
and I am deleting in destructor.It is showing breakpoint is due to corruption of heap.How are you deleting it ? like this :
delete [] m_myStatic;
This signature was proudly tested on animals.
-
I have created member variable
CStatic *m_myStatic
;,I am allocating memory like thism_myStatic = new CStatic[m_filecount];,
and I am deleting in destructor.It is showing breakpoint is due to corruption of heap.I see, well, you need to delete an array -as Maximilien already pointed out- like this:
delete []m_myStatic;
. Otherwise, heap corruption can be caused by indexing out of your array, so you try to write items in the array which are not in the array at all, for example:int *int_array = new int[5];
int_array[10] = 4;> The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <
-
I see, well, you need to delete an array -as Maximilien already pointed out- like this:
delete []m_myStatic;
. Otherwise, heap corruption can be caused by indexing out of your array, so you try to write items in the array which are not in the array at all, for example:int *int_array = new int[5];
int_array[10] = 4;> The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <
-
This is not related at all. How you use an array has nothing to do with how you destroy it.
He said he gets "corruption of heap", that -as far as i know- can be caused by what i said there. The question wasn't specifically "how to delete an array".
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <
-
He said he gets "corruption of heap", that -as far as i know- can be caused by what i said there. The question wasn't specifically "how to delete an array".
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <
Code-o-mat wrote:
He said he gets "corruption of heap"...
When he deletes, not accesses.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
-
He said he gets "corruption of heap", that -as far as i know- can be caused by what i said there. The question wasn't specifically "how to delete an array".
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <
-
Code-o-mat wrote:
He said he gets "corruption of heap"...
When he deletes, not accesses.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
Correct me when i am wrong but -at least in debug- when you allocate an array using new, the system will allocate somewhat more bytes than explicitly needed by your array and will place some special information infront and after your block. When you delete the array the system will check these special values infront and after the array and if it does not find what it expects it will complain about it because this probably means you wrote to memory you should not have written to. True, the example there was a bad one, i should have wrote
int_array[5] = 4;
instead ofint_array[10] = 4;
, because 10 is WAY after the lest element of the array...> The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <
-
Lol! My bad! I was reading your 'Otherwise' as 'if you don't delete scalar you will get memory corruption'.
Guess i should express myself more clearly, sorry... :)
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <
-
Correct me when i am wrong but -at least in debug- when you allocate an array using new, the system will allocate somewhat more bytes than explicitly needed by your array and will place some special information infront and after your block. When you delete the array the system will check these special values infront and after the array and if it does not find what it expects it will complain about it because this probably means you wrote to memory you should not have written to. True, the example there was a bad one, i should have wrote
int_array[5] = 4;
instead ofint_array[10] = 4;
, because 10 is WAY after the lest element of the array...> The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <