Retrieving a memory can modify its influence on subsequent behavior. Whether this phenomenon arises from modification of the contents of the memory trace or its accessibility is a matter of considerable debate. We develop a computational theory that incorporates both mechanisms. Modification of the contents of the memory trace occurs through classical associative learning, but which memory trace is accessed (and thus made eligible for modification) depends on a structure learning mechanism that discovers the units of association by segmenting the stream of experience into statistically distinct clusters (latent causes). New memories are formed when the structure learning mechanism infers that a new latent cause underlies current sensory observations. By the same token, old memories are modified when old and new sensory observations are inferred to have been generated by the same latent cause. We derive this framework from probabilistic principles, and present a computational implementation. Simulations demonstrate that our model can reproduce the major experimental findings from studies of memory modification in the Pavlovian conditioning literature, including dependence on the strength and age of memories, the interval between memory retrieval and extinction, and prediction errors following retrieval.