jrd wrote
In general, what's the best way of disposing/handling memory deallocation of an object in the context of needing to return it specifically for a function/method?
 
When a function returns an object that it created, it passes ownership of that object to the calling function.  The calling function must either dispose the object or return it.
class Whatever
{
    function Array Foo()
    {
        var Array result;
        let result = Array.new(10);
        ....
        return result;    // Calling function now owns the object.
    }
}
class Something
{
    function void Bar()
    {
        var Array thing;
        let thing = Whatever.Foo();    // Returns new Array object
        ....
        do thing.dispose();
        return;
    }
}
Sometimes you want to do this in the opposite direction; give an object that you created to a container object, and let the container take care of disposing what you put in it.
function void stash(Box box)
{
    var Thing foo;
    do box.add(foo);    // box now owns foo -- we can no longer touch it.
    let foo = 0;
    ...
    return;
}
function void trash(Box box)
{
    do box.empty();    // disposes all Things in box
    return;
}
--Mark