public void recycle(Resource<?> resource) {
        Util.assertMainThread();

        if (isRecycling) {
            // If a resource has sub-resources, releasing a sub resource can cause it's parent to be synchronously
            // evicted which leads to a recycle loop when the parent releases it's children. Posting breaks this loop.
            handler.obtainMessage(ResourceRecyclerCallback.RECYCLE_RESOURCE, resource).sendToTarget();
        } else {
            isRecycling = true;
            resource.recycle();
            isRecycling = false;
        }
    }
A class that can safely recycle recursive resources.
core/src/main/java/com/bumptech/glide/load/engine/ResourceRecycler.java