Edit: Was
I am a historian of the Middle East more than Africa, but it's the same basic principle in this case.
At least in terms of Palestine and their territories in that region, their primary reason for giving them up was WWII. Despite being an island nation, they were being bombarded by the German forces and couldn't afford to continue holding colonial territories. While much literature will argue that the British did this in support of a Jewish state, it is pretty clear that they were overwhelmed and flummoxed by the conflict between Arabs and Jews in Palestine and could not continue to moderate, leaving them no choice but to abandon the colonial project. Had they not been involved in WWII, they may have taken the same course of action, but they would have had a lot more resources with which to hold onto their colonial territory.
Whether or not this is the same for Africa, I'm not entirely sure, but I would venture a guess that there are significant similarities.