I'm working on a sort of file browser, where I use a flow layout control to show images. Each time I switch to a new screen I need to clear the control, and load new images (pictureboxes). I had been calling FlowLayoutPanel.Controls.Clear(), however I recently discovered that doesn't properly release resources (specifically, window handles) which causes an "error creating window handle" exception after about 10,000 pictures being loaded (which adds up after a few refreshes of the control).

I tried a for each control loop to .dispose() each picturebox, but the loop takes much longer to process, and ends up making each control disappear individually, rather than as a group. Is there a way to dispose the entire control collection at once? or is there another option that I hadn't considered? (for example, a way to keep using controls.clear, and manage resources in the background?)

Any ideas are very appreciated.