At the end of World War 2, with the three Axis powers defeated, Britain owed a huge debt to her Commonwealth partners and the USA, and a substantial debt to India. She could no longer hope to retain her Empire, due to the enormous financial restraints that had been placed upon her and India was calling for Freedom, led by Gandhi.
The main reason for India not becoming a self-governing country before the war, was that Britain had held the majority of India's foreign debt and the second, was that before the war, there were nowhere near enough trained Indian military officers to take over the Indian army and provide for India's defence. At the end of the war, Britain was a debtor to India, and the Indian army had been battle-hardened against the Japanese and Germans in some of the fiercest and most brutal cross-country fighting any army had endured. With over 15,000 trained Indian officers there were enough to fill out the command structure in all but the technical branches. The only real obstacle, apart from the British will to retain its empire, was the Hindu-Muslim cleavage.
Many in the British government and populous felt that should Britain withdraw from India, it should do so having brought a settlement between the two major communities, rather than withdrawing and leaving them to fight it out among themselves with consequent civil war or anarc.