❔ Image.FromStream() - OutOfMemoryException
The code above is a an implementation for application plugins that provide document previews, among other things. This method is called around 4000 times, and results in an
OutOfMemoryException
. As I've discovered, this is due to my misuse of loading images - GDI objects are depleted, thus, resulting in the exception. The question is, how do I dispose of the memory stream and image objects correctly?
Doing something like this:
... is not a good idea because the returned image
object is disposed of upon return, resulting in invalidly provided data.2 Replies