Memory Allocation Problem
hi,
I have 10 objects .
I m allocaing memory to each of them .
Memory is allocted properly .
But when i m destroying objects ( i m destroying it in reverse order )
it allows me to destroy only Some objects and gives the following error
If this ASSERT fails, a bad pointer has been passed in. It may be
totally bogus, or it may have been allocated from another heap.
The pointer MUST come from the 'local' heap.
if u know anything about this error , help me.
Can you show/explain how you are allocating and deallocating the memory as well as what the data type is. A little code would be best.
Init()
{
/* This is just in brief what my code is doing */
A , B , C , D , E are classes
other objects r also initialized befor this ..
Object_A = new ( A );
Object_B = new ( B );
Object_C = new ( C );
Object_D = new ( D );
Object_E = new ( 7 * sizeof ( E ) );
if i m deallocating memory here only then
it allows me to deallocate .
But If i run the program and trying to deallocate the memory
when program exits ,
that is after Update() and Render()
then it gives error while deallocating certain objects .
delete A ; // It will deallocate
delete B ; // It will deallocate
delete C ; // It is giving error
delete D ; // It is giving error
delete E[] ; // It is giving error
A bad pointer has been passed in. It may be
totally bogus, or it may have been allocated from another heap.
The pointer MUST come from the 'local' heap.
i have checked the pointer adrresses also they r same
while allocating and deallocating
}
{
/* This is just in brief what my code is doing */
A , B , C , D , E are classes
other objects r also initialized befor this ..
Object_A = new ( A );
Object_B = new ( B );
Object_C = new ( C );
Object_D = new ( D );
Object_E = new ( 7 * sizeof ( E ) );
if i m deallocating memory here only then
it allows me to deallocate .
But If i run the program and trying to deallocate the memory
when program exits ,
that is after Update() and Render()
then it gives error while deallocating certain objects .
delete A ; // It will deallocate
delete B ; // It will deallocate
delete C ; // It is giving error
delete D ; // It is giving error
delete E[] ; // It is giving error
A bad pointer has been passed in. It may be
totally bogus, or it may have been allocated from another heap.
The pointer MUST come from the 'local' heap.
i have checked the pointer adrresses also they r same
while allocating and deallocating
}
I assume that for Object_E you are trying to allocate an array:
That should do it :)
//allocatingObject_A = new A; Object_B = new B;Object_C = new C;Object_D = new D;Object_E = new D[7];//de-allocatingdelete A ; delete B ; delete C ; delete D ; delete E[] ;
That should do it :)
Don't you mean...
?
//allocatingObject_A = new A; Object_B = new B;Object_C = new C;Object_D = new D;Object_E = new E[7];//de-allocatingdelete Object_A ; delete Object_B ; delete Object_C ; delete Object_D ; delete [] Object_E ;
?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement