This paper is concerned with a nonlinear optimization problem that naturally arises in population biology. We consider the effect of spatial heterogeneity on the total population of a biological species at a steady state, using a reaction–diffusion logistic model. Our objective is to maximize the total population when resources are distributed in the habitat to control the intrinsic growth rate, but the total amount of resources is limited. It is shown that under some conditions, any local maximizer must be of “bang–bang” type, which gives a partial answer to the conjecture addressed by Ding et al. (Nonlinear Anal Real World Appl 11(2):688–704, 2010). To this purpose, we compute the first and second variations of the total population. When the growth rate is not of bang–bang type, it is shown in some cases that the first variation becomes nonzero and hence the resource distribution is not a local maximizer. When the first variation becomes zero, we prove that the second variation is positive. These results implies that the bang–bang property is essential for the maximization of total population.