Doris Lessing, the freewheeling Nobel Prize-winning writer on racism, colonialism, feminism and communism who died Sunday 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. And although some creative minds do peak in younger years, 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 the Arts and Culture at the National Center for Creative Aging.

Marilee Shapiro, 101, poses Thursday for a portrait next to one of her sculptures that is titled “The Way” at her home in Washington. (Matt McClain/The Washington Post)

“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.”

But repeating the same sort of creative pursuit over the decades without advancing your art can be like doing no exercise other than sit-ups your whole life, said Michael Merzenich, professor emeritus of neuroscience at the University of California at San Francisco and the 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. Try eating sea urchin, take up the piccolo, learn to speak Serbo-Croatian.

“Those people who have from the beginning developed complex lives with multiple interests and multiple talents, and continued to develop psychological complexity and tolerance for ambiguity, those people continue to do very well in later adulthood,” said Gary Gute, professor and director of the Creative Life Research Center at the University of Northern Iowa.

And although the slowing of motor skills means a musician might not be able to perform as quickly, Gute said, innovative performers such as Arthur Rubinstein find tricks to get around the physical difficulties. “As he got old, he couldn’t play a certain passage at the same pace, so several measures in advance of that, he would slow down before the hard part and then pick up the pace,” so it still sounded as fast.

Likewise, Marilee Shapiro, 101, a District sculptor who started her career in the 1930s, has had to make accommodations to age. At 88, the award-winning artist — she also made drawings and prints, has exhibited her work at museums and galleries across the country and will be part of an exhibit opening next week at Gallery Plan B in the District — realized that it had become difficult for her to physically handle her 4- to 5-foot 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 recalled. But once she learned Photoshop, she began manipulating and transforming her old drawings and prints into new images that look more like watercolors.

“It was just fascinating, and really seductive,” she said. “I believe that every time a new medium is discovered, it just starts a new range of possibilities, even if you’re just changing from one kind of paint to another.”

In fact, 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.

But after the early 40s, demyelinization starts to occur, with potentially interesting results for creativity.

“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 — essentially the difference between an inventor of the polio vaccine and an improvisational jazz musician.

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.

“I think for many older people there’s a time of great energy,” Trueblood said. “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.”

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. “The more I do the safe thing and only the safe thing, the more I tell myself there’s something I can’t do, my brain gradually retreats back to where I came from,” he said.

Actively engaging in learning throughout one’s lifetime can require more effort than it did throughout most of history. When average life spans hovered in the 20s, ill health or death often put an unceremonious end to a creative person’s output.

“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.