One of the most compelling characteristics of controlled processing is our limitation to exercise it. Theories of control allocation account for such limitations by assuming a cost of control that constrains how much cognitive control is allocated to a task. However, this leaves open the question of why such a cost would exist in the first place. Here, we use neural network simulations to test the hypothesis that constraints on cognitive control may reflect an optimal solution to the stability-flexibility dilemma: allocating more control to a task results in greater activation of its neural representation but also in greater persistence of this activity upon switching to a new task, yielding switch costs. We demonstrate that constraints on control impair performance of any given task but reduce performance costs associated with task switches. Critically, we show that optimal control constraints are higher in environments with a higher probability of task switches.