The posted approach here might still be valid, but note that the first pass is using num_workers=0 in order to add the loaded samples into the Dataset.
The following epochs might use more workers, where each process will create a copy of the complete Dataset, which would increase the memory usage by num_workers.
The linked post uses the shared arrays to directly paste the loaded samples into it using multiple workers.
Let me know, if you encounter any issues.