Fatal error on delete operator

I’m writing a class and I need to initialize a raw c++ pointer, so in the header I’ve:


class TestCacheAllocator* gCacheAllocator;

And I’ve wrote this functions into the .cpp file



void FPhysXRummy::Init() {
	gCacheAllocator = new TestCacheAllocator;

}

void FPhysXRummy::Term() {
        if(gCacheAllocator)
	    delete gCacheAllocator;
}


The problem is that I receive a fatal error on function Term, at this line “delete gCacheAllocator;”

As you can see the pointer is exists, so why the engine crash at this line?

Does the class ‘TestCacheAllocator’ have any definition anywhere or is it just a declaration? As far as I know, you can’t call ‘Delete’ on an incomplete type.

Calling delete without clearing the pointer looks like a recipe for disaster and it’s safe to call delete on a nullptr:


void FPhysXRummy::Term()
{
    delete gCacheAllocator;
    gCacheAllocator = nullptr;
}

The error was generated elsewhere, Thanks for response!!