Are there any methods like isDestroyed or isDisposed to detect whether some object is destroyed or not?

Andrey Derzhavin via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Dec 12 23:03:22 PST 2014


Hello!

We have object, for example, objA.

ObjectAType objA = new ObjectAType(...);

// we have a many references to objA

void someFunction1(...)
{
    // destroying the objA
    destroy(one_of_the_refToObjA);

    //........
}


void someFunction2(....)
{
    // "segmentation fault" if the objA is destroyed
    another_refToObjA.method1();

    // I need a safe way (without using signals) to detect whether 
object
    // destroyed or not, like this
    // if (!isDestroyed(another_refToObjA))
    //   another_refToObjA.method1();

}

// call functions
someFunction1(..);

// ..... some other operations...

// the objectA (objA) is destroyed, but debugger shows us a not 
null reference
// to that objA. However, when we try to call some methods of 
objectA or
// try to use it's variables we get a "segmentation fault" error 
(in
// someFunction2, when objA is destroyed).
someFunction2(...);

Thanks.




More information about the Digitalmars-d-learn mailing list