Sign in to follow this  
yogeshpatel4all

Memory Allocation Problem

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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
}

Share this post


Link to post
Share on other sites
Don't you mean...


//allocating
Object_A = new A;
Object_B = new B;
Object_C = new C;
Object_D = new D;
Object_E = new E[7];

//de-allocating
delete Object_A ;
delete Object_B ;
delete Object_C ;
delete Object_D ;
delete [] Object_E ;


?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this