The problem
When a user with many comments cancels his account, this could lead to php memory issues.
What are the steps required to reproduce the bug?
Cancel the user account of a User with thousands of comments with a php memory limit of 256M.
What behavior were you expecting?
The account will be deleted and all comments are unpublished/updated as well.
What happened instead?
You get a php memory error and not all comments of the canceled user are deleted/updated.
Reason
The code were the comments are loaded and updated has no chunking or batching mechanic.
$comments = entity_load_multiple_by_properties('comment', ['uid' => $account->id()]);
foreach ($comments as $comment) {
$comment->setUnpublished();
$comment->save();
}