Comedian George Hamm walked on stage at Portland’s Merrill Auditorium in December, grabbed a microphone and told more than a thousand people he had posted a suicide note on Facebook.

The line got a laugh, like nearly everything Hamm has said on stage during his 20-year career.

“Yeah, you laugh,” he said. “I got 28 likes.”

Bigger laughs followed.

The line was not planned. Hamm had been invited at the last minute to do a guest set by his friend, comedian Bob Marley, who does several holiday shows at Merrill each year. “It just came out,” Hamm said later. It was a bit of truth and pain shared in the setting where Hamm feels most at home.

Hamm, 50, posted his suicidal thoughts on Facebook two years ago, overwhelmed by depression, a mounting tax debt and a lack of work. He didn’t act on them. Friends who saw the note contacted him right away, and he took it down.

That Facebook post was one very serious moment in a decade or more of struggles for Hamm, as his mental health and his financial problems have combined to stall his career. Hamm has gone from performing 200 shows and making more than $40,000 in a good year to doing only a handful of shows a year and living in a friend’s spare room. He has no car, health insurance or steady income.

With the help of medication, Hamm is feeling better these days, and he is taking steps to clear up his tax debt. Though he performs infrequently, he continues to do free benefit shows for charities, something friends say is typical of his generous nature. Hamm’s ultimate goal is to be back in front of audiences on a regular basis. He may be Maine’s second-best known comedian behind Marley, but fellow comics – Marley included – say Hamm is the most naturally gifted funnyman they know. For Hamm, performing is about more than doing what he’s made to do. Comedy lifts him up, and he knows it lifts others, too.

“People have come up to me and said, ‘I had the worst week ever, but your show made me forget about it,’ ” Hamm said. “I’ve done that for myself. Things can be going really bad, but I can turn my bad day into a good day once I get on that stage. It’s the safest place I know.”

When comedian Robin Williams took his own life six months ago, after a long struggle with depression, people around the world were stunned because Williams was so successful and so funny. Hamm said he was “devastated” by the news. Both Hamm and Marley, like many comedians, viewed Williams’ death with great empathy.

“It takes a warped mind to do what we do,” Marley said. “Comedians aren’t up on stage in front of strangers because everything is OK.”

The link between comedians and mental illness is not simply anecdotal. Researchers at the University of Oxford in England asked more than 500 comedians to complete a questionnaire measuring psychological traits and found the comedians had many that are associated with forms of mental illness, particularly an inability to feel pleasure and impulsive extroverted tendencies.

Gordon Claridge, emeritus professor of abnormal psychology at Oxford, said in an email that the study, published last year, revealed among participants “the use of comedy as a way to escape inner demons and the self-medication that it confers.”

Talking about his personal problems on stage comes natural to Hamm, but talking about them in other venues is tough. He has struggled with sharing his difficulties publicly, worried about how people would react. He decided that sharing his story here might bring some awareness to the crippling effects of depression and inspire some people to get help.

“I have mental health issues, but I take responsibility. I drank a lot at times, to self-medicate, and I’ve never been good with money,” he said. “Hey, listen. Everybody’s got problems. The thing is to just not give up, right? I don’t want to give up – just hold on one more day. Just hold on.”

FUNNIEST MAN IN THE ROOM

Hamm’s great skill as a comic is observation. He can see a funny line in almost any moment, even sad or scary ones. Or awkward ones.

While opening one of Marley’s annual holiday shows at Merrill Auditorium a few years ago, Hamm’s act was interrupted by a group of late arrivals who were talking loudly and slow to take their seats. When Hamm asked the people if they realized he was performing, one woman said: “We just came down from Falmouth. We’re here to see Bob.”

Hamm replied: “Take it easy, Falmouth, you’ve got a Wal-Mart in your town just like everyone else.”

“George Hamm throws away more jokes than most comics can write,” said Marley, who has achieved national success thanks to a combination of talent, preparation and a tireless work ethic. “I’ve always looked at him and thought, ‘If I had what he has, I’d be on a different level.’ I work constantly and do a pretty good job, but he’s more raw funny than me, or any comic in the room.”

Hamm spent much of his childhood in Munjoy South, low-income housing at the base of Munjoy Hill in Portland’s East End. His family moved to the apartments after a history of seizures and a car accident made it difficult for Hamm’s father, a truck driver for a moving company, to work. His father died in 1996.

Hamm is the youngest of four surviving siblings. He had a younger brother, Michael, who died as an infant. His family has a history of mental illness, said Byron Hill, 63, Hamm’s brother from their mother’s previous marriage. Their mother had bouts of depression but was also known as someone who could make people laugh with her unfiltered, blunt takes on things.

Hill said that once Hamm took his mother to a medical facility for shock treatments and ran into an aunt there, also getting shock treatments.

“Boy, some family reunion,” Hamm told his brother.

EARLY DAYS IN HIS CAREER

Sports kept Hamm busy as a youngster. He played several before concentrating on basketball at Portland High. He remembers being captivated by black-and-white reruns of “The Honeymooners” TV show from the 1950s, with Jackie Gleason. Gleason had a booming voice and an expressive face, and he was a master of broad physical comedy. Hamm’s stage persona includes those traits.

Hamm started dabbling in comedy when he joined the service after high school, mostly just “razzing” fellow Marines for laughs, while stationed in Hawaii. When he finished his service in the early 1990s, he became a bouncer at Three Dollar Dewey’s in Portland.

Marley, whom Hamm had befriended in high school, invited Hamm to come along to open mic nights at clubs around Greater Portland. Within a few months, Marley, Hamm and two other local comics were booking themselves as a package show at venues around the state.

Marley’s name recognition grew, and he eventually moved to Los Angeles, appearing on TV shows such as “The Tonight Show” and performing around the world. Hamm opened for Marley a lot over the years, but also headlined his own shows. He performed around the country, including in Las Vegas, New York and Los Angeles, sometimes opening for nationally known comedians such as Kevin Nealon and Jay Mohr, both alumni of “Saturday Night Live.”

WHEN PROBLEMS EMERGE

It was around 2004 that Hamm’s current tax problem began. He didn’t put money away to pay his income taxes. He drank too much at times and gambled, which didn’t help his finances.

The tax problem “snowballed” over a period of years, Hamm said, to the point where some of his wages were garnished. The recession made it hard to get gigs. But he also missed or canceled performances because of bouts with depression, he said. Since he began performing less, Hamm has had a variety of day jobs, including driving a taxi and working event security. Crowd anxiety made the security job impossible.

When his car broke down a few years ago, he couldn’t buy a new one. He hasn’t had his own apartment for several years. He’s been staying at a family friend’s house in Cape Elizabeth for the past several months.

Hamm is reluctant to talk about his tax problems in too much depth, but he and his brother say they are working on a resolution.

Hamm had long experienced what he calls “melancholy,” he said, and he recognized that he drank heavily at times to deal with social situations. As his tax problems and work problems grew each year, Hamm realized he needed help. He began treatment for depression and anxiety, including medication and visits to a therapist, a few years ago. But today, without a car, he makes it to therapy infrequently.

Hamm, who has never been married and is not in a long-term relationship, says that he can’t predict what will trigger his depression or anxiety. And he isn’t sure that any specific events in his past are directly connected to episodes. Like most people with clinical depression, Hamm says he doesn’t know when it will hit him.

“You don’t know when it’s going to come, and when it does, there’s nothing anybody can do,” he said. “No one knows the pain you have.”

Recently, Hamm said, he felt anxiety during intermission at a show he was performing. He felt great on stage. After the show, while talking to an old acquaintance, he suddenly felt anxious again and left abruptly, without explanation.

“I know it’s hard for people to understand, and I can’t really explain it, but sometimes I just have to take myself out of situations,” he said.

Looking back, Marley said, he saw signs of Hamm’s depression and anxiety years ago. Hamm would sleep well into the afternoon on the day of a performance. And once, Hamm became extremely anxious about a performance in China, where the two had been hired to entertain Americans, despite the fact that, at that point in his career, he had been performing for years and had done hundreds of shows.

“I remember saying to him, ‘What’s the worst that can happen if they don’t like you in China?’ ” Marley said.

CRUDE JOKES, KIND DEEDS

On stage, Hamm can be crude and profane. In one of his milder jokes about bodily functions, he tells the audience he knows he’s out of shape because he can no longer hold his breath the entire time he’s in a porta-potty. He then demonstrates how he tries to hold the door open with his leg while inside.

Off stage, Hamm is thoughtful, reliable and often quiet.

Besides performing, his favorite activity these days is painting. He keeps an easel, tubes of paint and brushes in an unfinished attic space in the Cape Elizabeth home where he’s staying. He blasts classic rock on the radio and creates geometric shapes and patterns in bold colors. Just as Maine was about to be hit by 2 feet of snow last month, he finished a painting of black and gray squares and rectangles he called “The Nor’Easter.”

“I’ve never been a big artistic guy, but I just find it relaxing. I like getting all messy,” said Hamm, sitting on an overturned plastic pail in front of an easel. “It’s a different way of expressing myself. I’m kind of alone a lot, and this is a way of getting my mind off other things.”

Last summer, while Hamm was struggling to find a place to live, friends Michael and Lisa Donahue asked him for a big favor. Hamm sometimes babysat their four children, ages 6 through 13, when the couple wanted to go out. Their house had become a comfortable place for him – a family place – especially since Hamm’s mother died last year. Lisa revealed that she had a drinking problem and needed to go into rehab for 28 days. Her problem with alcohol began about two years ago, after her mother died, at the age of 56, from liver cancer.

Michael works full time at a car dealership. Who would be home with the kids?

“George came to our house every day to watch the kids, even with all he’s dealing with,” Michael Donahue said. “People don’t realize what a big heart he has. He’d do anything for us.”

Despite his lack of steady work and the tax debt, Hamm continues to do benefit shows for various causes. A couple of years ago, Marley remembers being struck by the fact that Hamm, struggling as he was, did a show to benefit Preble Street, a Portland provider of food, shelter and other services to people in need.

“He doesn’t take a dime from these shows. I remember saying, ‘Hammie, that’s really nice, but you need to make some money,’ ” said Marley. “He said he was just ‘securing my situation with Preble Street’ in case he ever needed a spot at the shelter.”

It was another funny line based on truth.

Last year, without money for rent, Hamm thought for a while that he might become homeless. He had to leave a friend’s basement with no place else to go. He got rid of many personal possessions and began looking for a backpack to live out of. He posted a message on Facebook asking if anyone had one to give away. A fan responded by buying Hamm a brand new backpack worth more than $150.

“I was terrified,” Hamm said of not knowing where he might live. “I didn’t think I’d be homeless for long, but still.”

A family friend ultimately offered him a room. Marley says he does not think Hamm will ever be truly homeless.

“He has too many friends,” he said. “Too many people love that guy.”

THE SHOW GOES ON

Hamm lingered in the cold vestibule at the Portland Eagles club as a powerful snowstorm raged outside the night before Thanksgiving. He had reserved an upstairs room at the club for his 15th annual “Have Your Hamm and Turkey Too” benefit show and did not want to cancel it. He was anxious about the show, pacing as he greeted audience members and often dashing outside to have a smoke in the snowstorm.

At times he stood by the door to unlock it for people, then directed them to an upstairs room for the show. Besides being the doorman, he had promoted the show himself, booked four other comics, arranged for door prizes of turkey and gift certificates, and asked friends to work as ticket takers. Hamm planned to donate proceeds to House in the Woods, a retreat for veterans in the northern Maine town of Lee.

Hamm paced as he waited for audience members to trickle in, worrying aloud that he wouldn’t get much of a crowd. He got on his phone several times to make sure the other comics were still coming.

At one point, a group of five or six people came in together, and Hamm’s face lit up.

“I’m glad you guys came. A few minutes ago, the only people here were my sister Mary, my brother Gary and my brother Byron,” he said. “I told them we could have just done this at somebody’s house. We’d all win a prize. It would be great.”

Hamm got a laugh from his guests. An hour later, on the Eagles club’s tiny stage wearing a gray hooded sweatshirt, he used the line about his family again, before the crowd of about 50 people. It got laughs then, too.

The other four comics that night each performed for about 20 minutes. Hamm was billed as the host but performed for at least 20 minutes between each set.

His friend Lu Kachmar, 50, who also struggles with depression, sat at a front table and became the butt of several jokes. She likes it when Hamm jokes about her, she said. She has even encouraged it.

“He used to want me to sit in back. He said it made him nervous for me to sit up front because he might use me in his act and upset me,” she said. “He’s very sensitive. The last thing he wants to do is offend someone.”

On this night, Hamm joked that Kachmar gets dates mixed up because she “buys all her calendars at Marden’s,” the Maine salvage store chain. Kachmar laughed from her belly and yelled responses. Hamm poked fun at virtually everyone in the audience, including all his siblings, and the audience of 50 people laughed nonstop. Outside, a heavy snow fell.

What could have been a bad night became a good one.