I’m counting one time D&D almost died. That was when TSR went under. Not sure about the other two times. 4E wasn’t one as it was still the #1 and for a time #2 selling RPG in the world.
Every fad fades. Even D&D. If Hasbro is smart they won’t bank on the extreme popularity of D&D lasting forever. As with most entertainment right now, D&D and MtG are taking hits because people are not isolating and are going back to the office. They kept producing mid-pandemic levels of product when the pandemic is ending.
I'm not including 4E as a time D&D almost died.
Basically in the 70's they ran out of money and the Blumes put money in essentially Gary lost control of D&D at that point. That's the 1st time.
The other time was 85 when the Blumes sold to Lorraine and her money bailed D&D out leading to Gary's eviction.
So basically without other people's money D&D would have died.