Fix garbage collection of shared data. #1348