note description: "[ Safe version of DISPOSABLE. ]" legal : "See notice at end of class." status : "See notice at end of class."; author : "Paul Bates (paul.a.bates@gmail.com)" date : "$Date$" revision: "$Revision$" deferred class SAFE_DISPOSABLE inherit DISPOSABLE rename dispose as unmake export {NONE} all end USABLE_I feature {NONE} -- Clean Up frozen unmake -- GC finalization call. local retried: BOOLEAN do if not retried and not is_zombie then safe_dispose (False) end rescue retried := True retry end frozen clean_up -- Resets state when `safe_dispose' raises an exception. local retried: BOOLEAN do if not retried then safe_clean_up end rescue retried := True retry end feature -- Clean Up dispose -- Action to be executed just before garbage collection -- reclaims an object. local retried: BOOLEAN do if not is_actively_disposing then debug ("trace") print ("Disposing of {" + generating_type + "}.%N") end is_actively_disposing := True if not retried and then not is_zombie then safe_dispose (True) elseif not retried then debug ("trace") print ("Warning {" + generating_type + "} has already been disposed!%N") end end clean_up is_zombie := True is_actively_disposing := False end ensure then is_zombie: (not is_actively_disposing implies is_zombie) and (is_actively_disposing implies not is_zombie) not_is_actively_disposing: is_zombie implies not is_actively_disposing rescue retried := True retry end feature -- Status report is_zombie: BOOLEAN -- Has `Current' been disposed of? feature -- Status report is_interface_usable: BOOLEAN -- do Result := not is_zombie ensure then not_is_zombie: not is_zombie end feature {NONE} -- Status report is_actively_disposing: BOOLEAN -- Indicates if `Current' is actively being disposed of feature {NONE} -- Implementation safe_dispose (a_disposing: BOOLEAN) -- Action to be executed just before garbage collection -- reclaims an object. -- Effect it in descendants to perform specific dispose -- actions. Those actions should only take care of freeing -- external resources; they should not perform remote calls -- on other objects since these may also be dead and reclaimed. -- -- `a_disposing': True if Current is being explictly disposed of, False to indicate finalization. require not_is_zombie: not is_zombie deferred end safe_clean_up -- Resets state when `safe_dispose' raises an exception. do end end