Well i guess i ll have to make a trilogy related to the question of mine found at Out of memory e开发者_StackOverflowxception while loading images
So here comes the second part.
According to the answers - comments found to the post mentioned above, sooner or later any computer will run out of memory while executing my code. :(
But thanks to Google i found a way of applying WrappingStream Implementation. where according to the writer
The BitmapImage keeps a reference to the source stream (presumably so that you can read the StreamSource property at any time), so it keeps the MemoryStream object alive. Unfortunately, even though MemoryStream.Dispose has been invoked, it doesn't release the byte array that the memory stream wraps. So, in this case, bitmap is referencing stream, which is referencing buffer, which may be taking up a lot of space on the large object heap. Note that there isn't a true memory leak; when there are no more references to bitmap, all these objects will (eventually) be garbage collected. But since bitmap has already made its own private copy of the image (for rendering), it seems rather wasteful to have the now-unnecessary original copy of the bitmap still in memory.
So here are a couple of questions i have. (And Before starting down-voting please keep in mind that i am a newbie!)
Could i use the WrappingStream class to avoid out of memory errors? If the first one is true, how can i adopt it and make it work with my example?
Thank you
Could i use the WrappingStream class to avoid out of memory errors?
No, it is aimed at a different problem.
System.Net.Http.Formatting.Internal.DelegatingStream should fit the bill. Too bad Microsoft hasn't made this class public in the framework.
https://github.com/ASP-NET-MVC/aspnetwebstack/blob/4e40cdef9c8a8226685f95ef03b746bc8322aa92/src/System.Net.Http.Formatting/Internal/DelegatingStream.cs
精彩评论