Fix the increasing allocating memory problem

Maximum memory of list will be the maximum of list length