Memory allows us to draw on past experiences to inform behaviour in the present. However, memories rarely match the situation at hand exactly, and new situations regularly trigger multiple related memories where only some are relevant to act upon. The flexibility of human memory systems is largely attributed to the ability to disregard irrelevant, but salient, memories in favour of relevant ones. This is considered an expression of an executive function responsible for suppressing irrelevant memories, associated with the prefrontal cortex. It is unclear to what extent animals have access to this ability. Here, we demonstrate, in a series of tool-use tasks designed to evoke conflicting memories, that chimpanzees and an orangutan suffer from this conflict but overcome it in favour of a more relevant memory. Such mnemonic flexibility is among the most advanced expressions of executive function shown in animals to date and might explain several behaviours related to tool-use, innovation, planning and more.