Doris Lessing, the freewheeling Nobel Prize-winning writer on racism, colonialism, feminism and communism who died last month at age 94, was prolific for most of her life. But five years ago, she said the writing had dried up.

"Don't imagine you'll have it forever," she said, according to one obituary. "Use it while you've got it because it'll go; it's sliding away like water down a plug hole."

Does creativity have an expiration date? The question arises each time an artistic luminary retires: In the past year, authors Philip Roth and Alice Munro announced that they would stop writing after decades of prodigious output; he was 79, she was 81, and their declarations piqued fears in older artists that they, too, might run out of ideas or energy.

We are used to wunderkinds, Mozarts and Zuckerbergs whose innovations in classical music and social media in their 20s transformed the culture. But the origins of creativity are complex, influenced by societal, emotional and neurological factors. Although some creative minds do peak early on, the trajectory is often not straightforward.

"I was not happy to see [Lessing] say that at the end," said Joan Jeffri, founder and director of the Research Center for Arts and Culture at the National Center for Creative Aging. "Look at Norman Mailer. He had no teeth left and he was walking with two canes, and he was still writing."

With increased longevity and the aging of the baby boomers, a generation that gained a reputation in the 1960s for valuing creativity across genres from electric guitar solos to psychedelic art to nontraditional living arrangements, the questions have become more pressing. The National Endowment for the Arts is coordinating an interagency task force, which includes the National Institute on Aging, to look into how creativity can be fostered throughout a person's life.

"Enhanced creativity is associated with greater satisfaction," NEA research director Sunil Iyengar said.

Dementia or brain damage can affect creative output. But in a healthy brain, decline is not a given, said Mark Walton, author of "Boundless Potential: Transform Your Brain, Unleash Your Talents, Reinvent Your Work in Midlife and Beyond."

"What's really interesting from the neuroscience point of view is that we are hard-wired for creativity for as long as we stay at it, as long as nothing bad happens to our brain," Walton said. (Lessing had a stroke in the 1990s, which may have contributed to her outlook.)

The type of discipline also matters. "Large creative breakthroughs are more likely to occur with younger scientists and mathematicians, and with lyric poets, than with individuals who create longer forms," said Howard Gardner, professor of cognition and education at the Harvard Graduate School of Education.

In fields like law, psychoanalysis and perhaps history and philosophy, on the other hand, "you need a much longer lead time, and so your best work is likely to occur in the latter years," Gardner said.

There's some truth to what Lessing said. "You should start when you are young," Gardner said. "But there is no reason whatsoever to assume that you will stop being creative just because you have gray hair."

Repeating the same sort of creative pursuit over decades without advancing your art can be like doing no exercise other than sit-ups your whole life, said Michael Merzenich, author of "Soft-Wired," a book about optimizing brain health. One-trick artists "become automatized, they become very habit-borne," Merzenich said. "They're not continually challenging themselves to look at life from a new angle."

To stay creative and original in later life, be willing to do new things.

Marilee Shapiro, 101, a sculptor in the District of Columbia who started her career in the 1930s, has had to make accommodations to age. At 88, the award-winning artist realized that it had become too difficult to physically handle her large bronze sculptures. So she took a course in computer design.

"My colleague students were about 21, and they knew how to start a computer. I didn't, so it was very challenging and very frustrating," she said. But once she learned Photoshop, she began transforming her old drawings into images that look more like watercolors. "It was just fascinating, and really seductive."

The science behind aging

A bit of brain degeneration can actually work to one's advantage.

People tend to excel at math and science early on partly because, studies show, the frontal lobe is still building myelinization — the insulating sheath around axons in the brain — through one's early 40s, said Rex Jung, assistant professor in the department of neurosurgery at the University of New Mexico. Better myelinization means more effective transmission of messages, leading to more precision and focus.

After the early 40s, demyelinization starts to occur, with interesting results.

"That's where artistic expression perhaps benefits from demyelinization," Jung said, noting that less efficient connectivity can mean a loosening of associations that allows ideas to flow more freely. Older people might benefit from more continuous idea generation rather than "one great idea that's going to win the day," he said.

In fact, the looser frontal lobe organization may heighten creativity in older people. "You have lots of data at your hands, and you have … fewer brakes on your frontal inhibitors, and you're able to put things together in more novel and useful ways," Jung said. "When you see an increase in people's creative undertakings in retirement, it may not be just because they're retired and have more time on their hands; it may be because the brain organization is different."

Older artists can also be galvanized by their own sense of mortality. Valerie Trueblood, 69, a Seattle writer who did not publish her novel, "Seven Loves," and two short story collections until her 60s, said age can bring greater urgency to the creative process.

"You see the end of it, you just see the brevity of life more acutely when you're older, and I think it makes you work harder and be interested in making something exact and completing it," Trueblood said.

Looking for new challenges

In the end, society's stereotypes about aging may turn out to be the biggest creativity killers.

"There is this powerful cultural message that this is the fate that awaits one, and some people subscribe to that," Merzenich said, adding that the idea that old age is a time to kick back and stop doing difficult things is "deadly" and can be self-fulfilling.

"The learning machinery used to be engaged almost continuously when we were children, but now it is hardly ever engaged," he said, adding that closing oneself off from new challenges causes the brain to regress to a childlike state.

Actively engaging in learning throughout one's lifetime can require more effort than it did throughout most of history.

"Now people are living longer, so this is a big experiment," Jung said. "We'll see if the great writers of our time are just going to flame out or if they're going to taper off over time."

Even the tapering off might not always be so clear-cut. Munro, who won the 2013 Nobel Prize for literature, hinted last month that she may not be done yet.

Despite her earlier declaration, she said, the ideas keep coming.