> No, explicitly running Collect() is normally a bad idea - it will
> adversely impact the performance of your code and can cause other
> problems.
That may depend on the situation. I found out in a DirectX application
that has to run for long stretches of time (12 hours or more of
uninterrupted D3D rendering in an applications that's controlled by events
it receives at a constant rate of several events/second), it's better to
force it at regular small intervals to prevent it from causing a noticeable
load on the system when it finally does it by itself.
> The best way that I have found to handle this problem is to load the
> image from a stream object that you control instead of directly from a
> file. This way you can use the image as long as you need, but close and
> dispose the stream as soon as you are done reading it.
I noticed it in a test program I wrote to find the best way to handle the
TWAIN capture, but the real app saves and reads small jpegs into/from a
database (ID photographs in a people database). I was already planning to
load them into a byte array for doing the database side and make a memory
stream out of the same array for copying into the picturebox, so that would
automatically become the solution.