layout: Implement reference counting for flows

r? @glennw