As per Lord Mahavir,
the only way to free oneself of this Karmic cycle is the way of Samyak Darshan, which means adopting the right faith,
Samyak Jnana, which means seeking the right knowledge and Samyak Charitra, which means having the right character.