At 11:48 AM -0600 4/28/05, Luke Palmer wrote:
Robin Redeker writes:
 This should actually be, to prevent the resource from leaking:

     {
       my $s = new CoolClass;
       eval {
         ... do stuff that may throws ...
       };
       destroy $s;
     }

Or, with the "block hooks" that I keep claiming makes timely destruction almost never needed, it is:

    {
        my $s = new CoolClass;
        # ... do stuff that may throw ...
        LEAVE { destroy $s }
    }

This destroys properly and even propagates the exception.

Actually it destroys improperly, since it destroys unconditionally, which is likely wrong. The right thing is to have the constructor for CoolClass tag its constructed object as needing expedited destruction and have the language compiler emit conditional sweep ops as part of its block finishing code.


Explicit destruction like that will clean up the object even if there are outstanding references, which is likely the wrong thing to do.
--
Dan


--------------------------------------it's like this-------------------
Dan Sugalski                          even samurai
[EMAIL PROTECTED]                         have teddy bears and even
                                      teddy bears get drunk

Reply via email to