Like If Metagross had the Steel gem and used Meteor mash then missed. Or had the ground gem and used Earthquake on a flying type. Or He uses any of them and the foe uses Protect.
The Gem won't disappear because the are only used up when doing damage. If a move misses, is ineffective, of is stopped by Protect/ Detect, the Gem won't disappear.