@Override
    public Optional<Graph> getGraph() {
        final Optional<Graph> optionalGraph =  Optional.ofNullable(this.graph);
        if (!optionalGraph.isPresent() || optionalGraph.get() == EmptyGraph.instance()) {
            final TraversalParent parent = getParent();
            if (parent != EmptyStep.instance())
                return parent.asStep().getTraversal().getGraph();
        }
        return optionalGraph;
    }
Determines if the traversal has been fully iterated and resources released.
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversal.java