AnOn Drupal 8, an other way is to delete multiple entities without loading them all at a time but by chunk.
You can use less memory and have great performance :
$nids = \Drupal::entityQuery("node")
->condition("type", "my_bundle")
->execute();
$storage_handler = \Drupal::entityTypeManager()->getStorage("node");
if (!empty($nids)) {
foreach (array_chunk($nids, 50) as $chunk) {
$nodes = $storage_handler->loadMultiple($chunk);
$storage_handler->delete($nodes);
}
};
For more convenience, you can trigger it inside drush command php-eval :
drush php-eval '$nids = \Drupal::entityQuery("node")->condition("type", "my_bundle")->execute(); $storage_handler = \Drupal::entityTypeManager()->getStorage("node"); if (!empty($nids)) { foreach (array_chunk($nids, 50) as $chunk) { $nodes = $storage_handler->loadMultiple($chunk); $storage_handler->delete($nodes); }};'