I have a function with a loop that in the loop calls a subfunction to update a database. The subfunction use a query that connects with \Drupal::database() and everything sems to work fine. But, when the loop ran into thousands of instances, it crashed and it turns out there is a memory leak for every \Drupal::database() you call since the memory is not released at the end of the function.
This is my context: In Drupal 8.7.5 I've set up an additional database in settings.php that is my old Drupal 7 db so that I can make some targeted migrations from it.
This works in mysql:
select * from file_managed as f
left join field_data_field_person_photo as p on p.field_person_photo_fid = f.fid
where p.entity_id = 500;
Which returns the values I expect. Now, inside Drupal 8 I attempted this:
the following is my code, I have just pasted the part where I am having trouble:
<?php
namespace Drupal\heritage_bulk_upload\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Url;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Archiver\Zip;