memory: add reference counting to FlatView