As an Indian I have wondered why European colonialists decided to settle in Africa ( South Africa , Namibia) but left promptly from Asian countries upon Independence.
During the period of European colonial expansion, the Indian subcontinent was already home to heavily populated societies that had achieved considerable technological advances, developed important commercial infrastructure, and had long histories of being organized into various polities and controlled by different empires (most of which were already connected with Europe in some manner). But, unlike India, much of sub-Saharan Africa's societies were comparatively undeveloped and many parts of the continent were only sparsely populated.
In answering this question, I think it’s important to first note that colonialism manifested itself differently depending on the characteristics of the areas that were colonized. At a high level, we can think about colonialism as having been either settler-based, which supported large-scale European immigration (for a variety of reasons), or exploitation-based, which placed a greater emphasis on shorter-term economic interests (e.g., control of trade or extraction of mineral wealth). In general, both the Indian subcontinent and sub-Saharan Africa were subjected to more exploitative forms of colonialism, albeit for different reasons.
In India, for example, the Portuguese began to assert themselves in the 16th century mostly to achieve dominance over what was a known area with established economic importance (e.g., strategic trade routes). India’s long history of economic development, as well as the size and social structure of its populace, would have provided a natural disincentive to large-scale European immigration. European emigrants, and their governments, were far more inclined to pursue permanent settlement in areas with an abundance of undeveloped, or "virgin", lands (e.g., the Americas). India didn’t have this sort of frontier status, which would have made it extremely difficult to supplant the existing population with European settlers in a meaningful way. Thus, the European powers in India would have been much more preoccupied with using their military might to force the capitulation of the existing societies and to ensure their continued subjugation, which proved to be a difficult task over the course of colonial rule. In general, most European colonies in Asia followed a similar paradigm.
Territories that were subjected to more exploitative forms of colonialism did receive limited numbers of European immigrants, but it’s important to note that their arrival was more of an administrative byproduct of colonization than permanent settlement (in the conventional sense). Most of those individuals would have arrived as members of the military or the colonial bureaucracy while only a select few members of the aristocracy, or well-connected gentry, would have been in a position to pursue local commercial interests. Such "immigration" rarely took the form of permanent settlement and the few multi-generational colonial families never lost their linkages to the home country (e.g., through schooling back home).
The most significant exception to purely exploitative colonialism in sub-Saharan Africa was in the southern part of the continent where large-scale European settlement was able to develop. This settlement began with the arrival of the Dutch in the mid-17th century in the area around the Cape of Good Hope. When the Dutch established the first permanent European settlement in 1652 around present-day Cape Town, the only natives they encountered were the pastoral Khoi people. At that time, much of the Khoi population was being decimated by smallpox, which was first introduced to the population in the preceding centuries by earlier European explorers. The remaining Khoi, who numbered no more than 15,000 when the Dutch first arrived, posed little threat to the colonizers who gradually annexed all of their lands in the Cape area during the following decades.
At the same time, the centuries-long migration of Bantu-speaking peoples had worked its way southward into present-day South Africa, but those peoples were located further to the east and had not yet come into contact with the Cape colonists. After the Khoi, the Xhosa, who were the closest Bantu-speaking group to the Cape, became the next African population that the European settlers encountered. But those first encounters occurred on the fringes of the growing Cape Colony and are thought to have only begun in mid-18th century, nearly 100 years after the first permanent European settlement in the Cape. As colonial expansion pushed further inward, the European settlers came into intermittent conflict with the Xhosa, and eventually the Zulus, and other African groups. In this sense, we can think about European settlement in southern Africa as being somewhat analogous to what transpired in the Americas.
So it’s important to remember that the present day demographics of South Africa can be seen as the culmination of different migrations undertaken by several groups, with the White population largely being descended from settlers who arrived to pursue opportunities in what were originally "virgin" lands. There’s a lot more to the story and there were a number of subsequent political and economic developments that have shaped the the area's development, but that’s the rough idea.
In short, the settler-driven colonization of southern Africa was made possible by a situation that was more akin to the frontiers of the New World, which would not have been possible in places like India and China.