Living in a couple is better than living alone, the researchers found
People who have a particular gene flaw and live alone in middle-age are at highest risk of developing dementia, researchers suggest.
The risk affects those who split up or were widowed from their long-term partner before the age of 50, Sweden's Karolinska Institute found.
Researchers say the APOE variant 4 is the most important genetic risk factor for Alzheimer's.
However, UK experts said there are many ways of reducing dementia risk.
As the world's population ages, dementia is a growing concern.
In 2005 around 25m people had dementia, but the number is expected to be around 81m by 2040.
The researchers studied 2,000 men and women from eastern Finland aged around 50 and again 21 years later.
They looked at their marital status and also carried out genetic tests to see if they carried the gene APOE variant 4.
People living alone in middle-age had twice the risk of dementia than those who were living with a partner.
But widows and widowers had three times the risk of dementia.
And those with the APOE gene variant who had lost their partners and remained living alone had the highest risk of all of developing Alzheimer's.
The team, led by Dr Krister Hakannson, said the results were important for preventing dementia and cognitive impairment.
They also said "supportive intervention" could be helpful for people who had lost a partner.
Writing in the British Medical Journal online, they said: "Living in a relationship with a partner might imply cognitive and social challenges that have a protective effect against cognitive impairment in later life."
They said the link with the APOE gene variant had to be replicated in other studies, but that it was in line with previous research findings.
In an editorial, also published online by the BMJ, Dr Catherine Helmer of the Universite Victor Seglen in Bordeaux, said: "One possibility is that the age and conditions of widowhood are crucial factors.
"Being widowed late in life, as were most of the people in previous studies, is perhaps less stressful - especially as the person is widowed for a shorter duration - and might thus not be a risk factor.
"Nevertheless, the hypothesis of a deleterious biological effect of widowhood remains to be proved, as does the possibility of genetic vulnerability as a link between widowhood and dementia."
But she said the link with the APOE variant should be treated "with caution", because this was an epidemiological study which looked at disease incidence in a population, and needed to be confirmed in further studies.
Dr Susanne Sorensen, head of research for the UK's Alzheimer's Society, said: "Inheriting the APOE gene is only one of many factors that can affect your overall risk of developing Alzheimer's."
She added: "Evidence suggests that remaining socially active may reduce your risk of dementia and living with someone is certainly a good way of doing this.
"However, single people shouldn't worry - there are many other ways to reduce your risk of dementia.
"The best evidence is around eating a Mediterranean diet, exercising regularly, and getting your cholesterol and blood pressure checked regularly."
Rebecca Wood, chief executive of the Alzheimer's Research Trust, said: "In societies where divorce and separation are growing trends, we need to examine how we help people adjust to living alone.
"Those who are widowed are at a much higher risk, and interventions soon after their loss may have a significant preventive effect."