In an ideal case I prefer enumerating over dataloader with a for loop.
But for a particular implementation, I need multiple batches within one iteration in a sequence.
To do this I use, next(iter(dataloader)) to get as many batches as I need within one iteration.
The issue is, this causes linear increase in RAM over iterations and epochs. Somehow, the memory is not cleared after every iteration.
Any way I can avoid using iter and get multiple batches within one iteration?
Found the problem which was causing memory leak. The code I was using also uses itertools cycle() to iterate over another dataloader which was causing the memory leak.
Using iter(dataloader) does not cause any memory leak.