Fix a bug in computing memory requirements