Distance from assailants is always desirable. Think miles. The problem is that it isn't always available, for one reason or another. When this happens, and unfortunately it happens frequently, assuming that you're not foolishly turning your back without the ability to run faster than the assailant and make it to minimum safe distance from weapons, you'll need your drawing hand to draw and bring the gun back to a far back hip shooting position, while the other arm if needed can deflect the assailant or perhaps do strikes.
In the event of a powerful grab attempt, techniques such as a kick to the knee and a 2 handed retention grip such as the CAR system uses come in handy.