Factor out some common functionality into Memory.Container.