I'm deleting multiple nodes like this:
$nids = [21,12,45,67]; // Just an example, this data comes from elsewhere $nodes = \Drupal::entityTypeManager()->getStorage('node')->loadMultiple($nids); \Drupal::entityTypeManager()->getStorage('node')->delete($nodes);
Drupal is running out of memory when deleting just 6 nodes.
I'm having this problem in general, not just when deleting, but any time I work with multiple nodes. The PHP memory_limit is 256MB and the server admin is reluctant to increase this. Even if it is increased, it's just postponing the problem - it might fail on 12 or 16 instead of 6.
Is there another way, e.g. to delete based on nid without loading the full node object and all of its fields? The deprecated
entity_delete_multiple appears to load the entities before deleting anyway. I suspect it has to because various hooks have to be called and it has to delete revisions and field data.
Or is there some special way I can code it to delete one node at a time and free each object afterwards to keep memory usage low?