-
Notifications
You must be signed in to change notification settings - Fork 204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Why will there be a memoryleak if I don't dispose the stream? #365
Comments
I posted this answer on SO some years ago. It should help explain: |
I know what will happen if you don't call dispose, that's why I am having this question. |
You have a case here; the documentation wording might be a bit clearer - basically the documentation is stating that there exists a safety-net finalizer that will prevent a memory leak in case you forget to dispose the stream. The documentation also states that you should treat forgetting to dispose the stream as a problem, that is why the library gives you a lot of support to track undisposed instances. The problem with finalizers is that you do not know when they will eventually run, so you might end up pooling up more resources than strictly required (imagine having 50+ free buffers waiting to be finalized and returned to the pool and still having to allocate extra buffers because the pool has been drained, then eventually the finalizers run and now you end up with a surplus of pooled buffers). Whether this is a serious problem, I guess it will depend on the use-case, the amount of free memory, and your own idiosyncrasies. The library will still greatly reduce strain on the garbage collector, but will not perform optimally. |
I don't quite understand. I thought the blocks are Garbage Collected if I do not dispose the stream. Why is there a memory leak?
Basically I am having trouble under this paragraph in the readme doc on this project:
If you forget to call a stream's Dispose method, this could cause a memory leak. To help you prevent this, each stream has a finalizer that will be called by the CLR once there are no more references to the stream. This finalizer will raise an event or log a message about the leaked stream.
So what the heck is it talking about? There will be a memory leak? Or could cause a memory leak depend on my Luck?
The text was updated successfully, but these errors were encountered: