Old Age Will Destroy Your Brain

Exercise correlates with a reduced risk of suffering dementia in later life, just as excess visceral fat is correlated with an increased risk of later developing dementia. The underlying mechanisms are somewhat different, but they both boil down to the quality of the blood vessels in your brain. Impaired blood vessels mean a lower blood flow or the breakages and lesions of vascular dementia - neither of which is good for you in the long term.

Another issue to consider in this context is the ongoing impact of atherosclerosis, the build-up of fatty material on blood vessel walls. This can result in sudden death due to blockage and rupture of larger deposits, but the condition harms your brain across the years leading up to that point:

Atherosclerosis, dementia, and Alzheimer disease in the Baltimore Longitudinal Study of aging cohort

We examined the relationship between systemic atherosclerosis, Alzheimer type pathology, and dementia in autopsies from 200 participants in the Baltimore Longitudinal Study of Aging, a prospective study of the effect of aging on cognition, 175 of whom had complete body autopsies. … we found that the presence of intracranial but not coronary or aortic atherosclerosis significantly increased the odds of dementia.

Just as for the other forms of damage to blood vessels in the brain mentioned above, atherosclerosis is largely something that you do to yourself as a result of your lifestyle. Being fat and sedentary will get you there. Unfortunately, the characteristic mitochondrial damage of aging also spurs the onset of atherosclerosis

Although (see table 1 of this paper) cranial atherosclerosis has a different mechanism and thus different risk factors than other atherosclerosis (frequently patients have one or the other but not both), you should indeed avoid getting fat, which increases the odds of it by 4-6 times.  You’re at risk for a severe stroke if you have cranial atherosclerosis.

Also, heavy smoking (even decades earlier) is at least as harmful to your aging brain as a sedentary lifestyle, probably for the same reason it’s a well known risk factor for stroke (it’s harmful to blood vessels).