Are you binge-snacking through your finals? You might be making your memory worse.

A new study from the University of New South Wales in Australia published in Brain, Behavior, and Immunity shows that just one week of eating an unhealthy diet is enough to cause lasting memory impairment in rats.

For a week, the rats were given access to a bottle of sugar water in addition to a healthy diet, or were fed a cafeteria-like diet loaded with cakes, cookies, and fat. Although only the rats on the cafeteria diet gained weight, both groups of rats had memory impairments compared with control animals who ate only healthy foods, suggesting that weight gain alone wasn’t to blame for their memory lapses.

Learn More: Are Your Kids Eating a Balanced Diet? »

The rats had little trouble with object recognition, a type of memory that involves a brain region called the perirhinal cortex. But they did far worse with place recognition, a type of memory that involves a brain region called the hippocampus, which is responsible for many types of memory formation, including retaining new facts.

Explore the Human Brain in 3D »

In the rats on the high-sugar or cafeteria diet, the researchers found that the hippocampus had become inflamed, impairing its function. The inflammation and memory damage lasted for at least three weeks after the rats were returned to a healthy diet.

Although rats aren’t a perfect model for humans, their hippocampus functions in very similar ways to ours. In humans and rats, the hippocampus not only helps us learn but also helps us navigate places and record events as they happen. Keeping it healthy is invaluable for learning and recall.

“A healthy diet is critical for optimum function,” said study author Professor Margaret Morris in an interview with Healthline. “Our data suggests that even several days of bad diet may impair some aspects of memory.”

The hippocampus is also used to regulate the body’s stress system. If it’s not able to do its job properly, stress can get out of control, dumping hormones into your bloodstream that will circulate back to the hippocampus and damage your memory further.

Know the Basics of Stress and Anxiety »

To complete the vicious circle, when stress levels are high, the body’s hunger systems shift. This causes you to selectively crave fatty and sugary foods.

Although a little junk food here and there won’t have too much impact on a young person, a lifetime of poor eating can add up. If your hippocampus doesn’t get a chance to recover from the sugary, fatty onslaught, the inflammation could become long-term damage.

“Some studies show a decline in cognition with aging, and it is possible that an unhealthy diet may be particularly unhelpful in this group,” said Morris. Older brains take longer to recover from insults such as hangovers, so they might also be more vulnerable to damage from a junk food diet.

As seniors living on their own lose mobility, some are more likely to eat pre-packaged foods, such as frozen dinners, which tend to be high in fat, sugar, and salt. So this finding might also help explain the role that diet plays in the development of memory impairment in diseases like Alzheimer’s.

Read More: Can Diet Help Prevent Alzheimer’s Disease? »