Memory is a fundamental component of learning, a process by which individuals alter their behavior through experience. Although memory most likely has explicit costs such as synaptic maintenance and metabolic demands, there are also implicit costs to memory, in particular, the use of information that is no longer appropriate or is incorrect. Specifically, the period of retrievability for memories, or "memory window," should be sensitive to the rate of environmental change of information stored in memory. Much empirical data suggest that memory length--this period of retrievability--changes with both the age and state of the individual. Here, we use a dynamic programming approach to examine how optimal memory retrieval might change within the lifetime of the individual learner. We find that optimal memory length varies with both age and state (e.g., energy reserves) of the organism and that features of the environment determine how this change in memory occurs. In our model, retrieval decreases as the environment becomes unreliable but roughly increases with the cost of living. Cost of living interacts with the state of the organism: with high cost of living, an organism in a very poor state should have a long memory length, but an organism in a very good state with low costs of living should have a short memory length. Finally, we find there are circumstances where it is optimal for memory retrieval to decline toward the end of the lifetime. Because this framework does not incorporate inevitable degradation of neural mechanisms, this result implies that memory loss with age might actually be adaptive. Copyright 2009, Oxford University Press.