CLASS* object;
// initializing
object = new CLASS;
//shutting down....
object = 0;
take note i forgot to do this,
delete object;
i just immedietly set it to 0, so what happened there? it worked out fine here..,
thanks,
CLASS* object;
// initializing
object = new CLASS;
//shutting down....
object = 0;
take note i forgot to do this,
delete object;
i just immedietly set it to 0, so what happened there? it worked out fine here..,
thanks,
The memory reserved for your object will remain reserved. The pointer actually points to the memory reserved for it, so when you set it to NULL before calling delete you lose the opportunity to release the memory.
If you place your code in loop, so that you keep reserving memory without deleting it - eventually you will run out. I.e.
CLASS object;
while(true)
{
object = new CLASS;
object = 0;
}
As to what happens to 'leaked' memory when your application terminates - that's a good question. I'm not actually sure. I think it could depend on your operating system as to whether it will know that it should be deleted or whether it just stays lost.
Does anyone know?
>I think it could depend on your operating system as to whether
>it will know that it should be deleted or whether it just stays lost.
It depends on the OS, but all of the mainstream and good operating systems will reclaim memory from your program when it ends. Though don't rely on this, because you can't be sure. Always free memory that you allocate.
-Prelude
My best code is written with the delete key.
ah oh yeah,
thanks!