The house of Harold T. Martin III is shown in Glen Burnie, Md., on Oct. 5. The federal government contractor is accused of stealing highly classified information. (Jose Luis Magana/AP)

An attorney for the former National Security Agency contractor accused of stealing unprecedented amounts of classified government data said at a hearing Friday that his client has a compulsive hoarding habit that runs in the family and should not continue to be detained.

But U.S. District Judge Richard D. Bennett declined a request that Harold T. Martin III be released from jail, ruling that he was a flight risk. Bennett affirmed a magistrate judge’s ruling from last week that Martin continue to be detained pending an eventual trial or resolution of the case.

The former contractor was arrested Aug. 29 at his home in Glen Burnie, Md., and charged in a sealed complaint with felony theft of government property and the unauthorized removal of classified materials, a misdemeanor. The complaint was unsealed this month when word of his arrest leaked out.

Talks between Martin and the government “have been less than satisfying,” Assistant U.S. Attorney Harvey Eisenberg told the court. “They’re not always productive.”

James Wyda, Martin’s attorney, portrayed his client as “completely engaged” in the process. “Mr. Martin,” he said, “is remorseful for the risk that he took with the government’s documents. He is ashamed of that. He is someone who, in every way, takes great pride in the mission of the intelligence community.”

Martin, who sat quietly at the defense table, is accused of taking 50 terabytes of data and “six full banker’s boxes’ worth” of documents over the years from a variety of agencies, including the NSA, the Office of the Director of National Intelligence and the Office of the Undersecretary of Defense for Intelligence.

Wyda conceded that Martin has taken classified material. But he said the former Booz Allen Hamilton employee was a “compulsive” hoarder, not a traitor.

He argued that the only consideration before the court was whether there is a “serious risk” that Martin would fail to appear in court if he is released — and not whether Martin is a danger to the community. The latter factor may be considered only in setting conditions of release, Wyda said in a filing earlier this week.

Wyda noted that Bennett had lived in the area for more than 20 years, that he has held a security clearance for 28 years with no issue and that he has no criminal history.

He acknowledged that Martin was taking medication for attention-deficit disorder, and said that was “one of the triggers for hoarding.” He said that Martin’s wife, Deborah Shaw, who sat in the audience, had tried to help Martin control his compulsive collecting. Martin’s mother was a hoarder, he said. And his sister “has challenges in this area.” Still, he said, there was no evidence that Martin intended harm with the hoarding. There is no evidence he passed any material to anyone else, including a foreign government, he said.

The judge cited several factors in his ruling that Martin not be released. One was the “egregious” nature of the offense. The weight of the evidence, he said, was “overwhelming.” Also, he said, Martin’s history and character gave him “great pause.” He said that the defense has pointed to mental-health issues but provided no professional analysis. “We have no idea of what we’re dealing with this individual here. None.”

He also accepted the government’s assertion that in the face of a likely conviction, Martin’s job opportunities will be “severely restricted,” which prosecutors argued would make him more apt to want to flee.

“The harm has already occurred in terms of the shock to the public and the shock to the intelligence community, in terms of loss of confidence to the public and loss of confidence to intelligence officials,” Bennett said.

The ruling was clearly disappointing to Martin. But as he was led away in handcuffs by a U.S. marshal, he mouthed a message to Shaw: “I love you, babe.”

Matt Zapotosky contributed to this report.