Search ProofOfProgress Blog

Thursday, February 11, 2016

Homebrew memory leak detection.

Having some type of memory leak detection that is only compiled in debug mode I think is a good idea.

NOT memory management. Because that would have to exist in both debug and release.
And memory managers would defeat the purpose of using a high-performance language like C++.

//For a class that has 3 pointers under it's ownership.
//Here is how we could delete it, and get a basic order-independent
//(combination based) hash to confirm the objects we think were deleted
//are deleted.
static uint32_t MyClass::deleteInstance(MyClass* c){

    uint num1 = OtherClass::deleteInstance(c->ptr01);
    uint num2 = OtherClass::deleteInstance(c->ptr02);
    uint num3 = OtherClass::deleteInstance(c->ptr03);
    uint finalNum = c.getObjectID();
    delete c;
    return (num1+num2+num3+finalNum);

No comments:

Post a Comment