I have a program that streams media, which creates two huge MemoryStreams, and then needs to zero them when done. The problem is, the memory does not seem to be reclaimed after I call BOTH MemoryStream.SetLength(0); and MemoryStream.Capacity = 0. GC.Collect() seems to solve the problem, but I have heard this is bad programming practice, because it causes all threads in the application to hang; although hung threads would not be a problem for the short time it would take to clear the memory. However, it would be nice if there was another workaround to the problem. Any suggestions?
I have a program that streams media, which creates two huge MemoryStreams, and then
Share
So there is no problem… Why do you think you need to force the GC to collect the memory at once? It will be done when the system deems it necessary. Don’t try to outsmart the GC 😉