The referee has full discretion on whether or not to use the vanishing Referee Spray, and opponents are required to retreat 10 yards from the spot of a free kick regardless of whether Referee Spray is used (unless the team awarded the kick elects to take a “quick” free kick with opponents still within 10 yards).
It is generally used when a free kick is awarded where a goal-scoring attempt is highly likely to develop, e.g., it is usually not used when a team is awarded a free kick in its own half of the pitch.
When the referee chooses to use the vanishing Referee Spray, he or she will usually mark the spot of the ball, then pace 10 yards in the direction of the attack, then spray a line marking that distance. Finally, the referee will indicate for the free kick to be taken, usually by blowing the whistle. The marks disappear in minutes.