[email protected], on 09 December 2012 - 05:01 PM, said:
the result, in terms of the event subscription, would be exactly the same, because the ffmpegproc object will still fall out of scope, and become unreachable from your code at the end of the BtnBeginVideoConvert_Click.
A using statement ensures Dispose() is called. That's all. Further, Dispose() is totally unrelated to the event subscription you made. Finally, Dispose() usually has only, at best, an indirect effect on garbage collection.
Calling Dispose() does not cause garbage collection to occur (unless someone explicitly coded it to do so, using GC.Collect()), or magically allow the object to be garbage collected. Dispose() is actually largely unrelated to garbage collection. Dispose() is about freeing resources that the garbage collector has no knowledge of how to free (file handles, database connections etc). Remember, garbage collection deals only with raw memory.
In my opinion, you are best off separating IDisposable and garbage collection in your mind. They compliment each other as an all round means of resource management, perhaps, and therefore there is the occasional small overlap between them, but there is generally no direct relationship between the two.
Thank you so much supernatural. So what you're saying is all objects get garbage collected when they go out of scope even if you don't dispose them or use using( ??
So even file browser dialogs and timers?
That said since my event has nothing to do with this garbage collection I still am not seeing why I shouldn't unsubscribe it at the end? Sorry supernatural. You've been an amazing help by the way those are really my last two questions regarding this.