/* Test various permutations of the destroy method */

/* First, the class that tracks when destroys are done */
class test {
    var myname = "";
    public proc create(name)
    {
        myname = name;
    }
    public proc destroy()
    {
        "Help!  My name is \"", myname, "\" and I'm being destroyed!\n";
    }
}

/* Test destroys in the context of class instances */
class other {
    var foo;
    public proc create()
    {
        foo = new test("other");
    }
}

/* Test destroys in the context of local variables being popped */
proc foo()
{
    var a;
    a = new test("foo");
}

proc main()
{
    var a;
    var arr;

    /* Test destroys in the context of local variables being overwritten */
    a = new test("a");
    a = nil;
    oadl::gc();

    /* Call the local-variable-popped test */
    foo();
    oadl::gc();

    /* Test destroys in the context of array elements being overwritten */
    arr = new Array(1);
    arr[0] = new test("arr[0]");
    arr[0] = nil;
    oadl::gc();

    /* Test destroys in the context of arrays being destroyed */
    arr[0] = new test("arr");
    arr = nil;
    oadl::gc();

    /* Test destroys in the context of containing objects being destroyd */
    a = new other();
    a = nil;
    oadl::gc();
}