Correct memory handling for comparator