public void release ( Collection < T > release ) { List < Ref < T >> refs = new ArrayList <> ( ) ; List < T > notPresent = null ; for ( T obj : release ) { Ref < T > ref = references . remove ( obj ) ; if ( ref == null ) { if ( notPresent == null ) notPresent = new ArrayList <> ( ) ; notPresent . add ( obj ) ; } else { refs . add ( ref ) ; } } IllegalStateException notPresentFail = null ; if ( notPresent != null ) { notPresentFail = new IllegalStateException ( "Could not release references to " + notPresent + " as references to these objects were not held" ) ; notPresentFail . fillInStackTrace ( ) ; } try { release ( refs ) ; } catch ( Throwable t ) { if ( notPresentFail != null ) t . addSuppressed ( notPresentFail ) ; } if ( notPresentFail != null ) throw notPresentFail ; }
Release a retained Ref to all of the provided objects ; if any is not held an exception will be thrown