What Does the Heart In Gyms Mean?
Solution 1:
The heart you are seeing above the Pokemon during gym battles is known as motivation. A Pokemon's motivation level determines how much "energy" it has left to fight. Once the motivation reaches zero, it gets knocked out of the gym and returns to its trainer.
From the Niantic help page:
Every Pokémon on a Gym has motivation, a measurement of the Pokémon’s desire to defend the location. Trainers from opposing teams battle to reduce the motivation of the Pokémon on the Gym. Pokémon gradually lose motivation over time and by losing battles against opposing team members. As a Pokémon loses motivation, its CP will temporarily decrease, making it weaker in battle. When a Pokémon’s motivation reaches zero, it leaves the Gym and returns to its Trainer the next time it loses a battle.