Blender (3.2.1) crashes while building previews for large amount of materials

I have a large archive of PBR materials, and I’ve developed a python script to take all the textures and make them into full materials ready to be used.
The problem is that when I mark all the ~900 materials as Assets, Blender begins to load each material’s textures to render the little preview you see in the asset browser, but it doesn’t seem to unload the previous material’s textures before moving on to the next one, leading to all my system ram (32Gb) to fill up in minutes and causing a crash.

Is this a bug or does Blender need to keep the textures in memory for whatever technical reason? Why can’t it load the textures, render the preview, and then dump the textures and only keep the little image it rendered?

Also, if I close blender before my RAM is full, upon re-opening the project the already rendered previews show up, but the rest of the assets just have a blank preview.