What can be done to mitigate this risk? I propose a dead man's switch method for ensuring that your body cannot continue living without you in it.
Death is a bad thing insofar as it cuts off a life and hence brings an end to everything good and meaningful in that life (relationships, doings, plannings, etc). But this allows that there can be worse things than death, i.e. cases in which living is so dominated by pain and suffering that its cessation would be a net improvement.
I propose the general principle that no one should have to suffer a fate that is worse than death. A practical implication of this principle is that everyone should have the right to death as an option, since only then can we be sure that no one who is alive is being forced to suffer something that they find worse than death. I think this is the intuition behind the assisted suicide movement, which has been gradually gaining legal standing across liberal democracies. Assisted suicide laws have so far been most helpful for those cases of net negative suffering that external observers find easiest to go along with: people with terminal illnesses who are also in great pain. Recently there has been a controversial extension to better fit the liberal principle that the individual must be the best judge of the question of whether their life has become worse than death, allowing those with chronic but non-terminal physical and psychological conditions access to a painless, guaranteed and dignified death.
Unfortunately the assisted suicide movement has so far not been much help to those who worry about dementia. This is because its commitment to respecting people's individual judgements and choices has been taken to require a rather rigorous consent procedure in which the petitioner must demonstrate their general mental competence and specific understanding of what they are asking for. This is obviously not possible for anyone suffering from late-stage dementia. Moreover, even though there is no longer a person present there remains a living sentient human body to which standard human/patient rights apply. Living wills do not suffice as a solution since medical professionals owe their duty of care to the patient before them rather than to the person they used to be. They lack the authority to act on behalf of the person who used to occupy the body where it would go against the interests of the sentient creature before them.
The result is that many people diagnosed with dementia must either exercise their right to die too early - while they actually still find their life worth living - or lose that right altogether.
It seems to me that there is a DIY alternative. The ethical rules that constrain 3rd parties don't apply to you. You don't have to ask anyone's permission and therefore don't fall into the consent trap. You are allowed to do what you like to your body now because it is yours. This includes doing things with long term negative consequences for your body's survival (such as smoking cigarettes or drinking dangerous amounts of alcohol). All you have to do is find a way to use your current power over your body to exercise control over what happens to it if you aren't there anymore.
Imagine that you have just been diagnosed with early stage dementia. Everyone would agree that you are competent to decide whether your life is worth living and also to make decisions about medical procedures. Therefore you should have the right to create a living will that will provide instructions directly to your body rather than passing a mere request to your doctor. This kind of living will takes the form of a dead man's switch: when your cognitive functioning declines past a pre-assigned level, your death would follow automatically.
There are various ways of making this work. For example, you could have a sealed poison pellet surgically inserted into your body together with some electronics that will cause a gentle poison to be released automatically unless a signal is received every 2 weeks. Then every week you would take a quiz to ascertain the state of your cognitive functioning, for example whether you can still remember your spouse and children. Think of it a bit like a CAPTCHA designed to tell if you are still the real you. Fail the quiz twice in a row and the poison pellet would automatically activate and your body would die in its sleep. Of course a living will can be altered if you change your mind while you are still able - surgeries can be reversed.
If you find the poison pellet idea ethically dubious, another option would be to reverse the mechanism and create a situation where your body depends on the continuation of something not to die. (This takes advantage of the distinction between causing harm and allowing harm to happen that bioethicists have an unfortunate tendency to hide behind.) For example, you could have an operation that curtails your heart's ability to regulate itself and also installs a pacemaker that offsets the damage and lets your heart function normally. (Yes, I know these examples are probably scientifically unsound, but the underlying idea should be feasible.) In this case failing the quiz would end the signal that keeps the pace-maker going and you would again die automatically, but this time from the interruption of your necessary medical treatment rather than by the introduction of a poison.
To sum up. It is not possible to guarantee that people won't suffer from a terrible condition like dementia. However, it is possible for a society to ensure that no one is forced to live a life that is worse for them than death. We can do this by putting into each individual's hands not only the legal right but also the real ability to make the choice for themselves.