@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void destroyInstance(final Object instance) { if (isManaged(instance)) { beforeDestroyInstance(instance); final Object unwrapped = maybeUnwrap(instance); final Deque<Factory<?>> factories = factoriesByCreatedInstances.remove(unwrapped); while (factories != null && !factories.isEmpty()) { final Factory<?> factory = factories.pop(); for (final DestructionCallback callback : destructionCallbacksByInstance.removeAll(unwrapped)) { callback.destroy(unwrapped); } factory.destroyInstance(unwrapped, contextManager); } afterDestroyInstance(instance); } }