Yes obviously that is why we have got something called 'Container' which is aware of all these things and taking care. You are NOT at all required to be bothered of how it handles and the ways to fine tune it.
Instead, you will end up building your own container.
If interested, you can read the container's documentation to get to know the strategy and/or algorithms being used if any. But trying to put your hands in to an already existing stuff, will yield nothing but reinventing the wheel.