You seem to be conflating several issues here:
- What's the difference between
using
and Dispose()
?
- When should you use
using
or Dispose()
?
- But what about that article that says
using
uses more memory?
The answers to the duplicate question tell you when to use using
rather than Dispose()
, so I won't repeat that here.
But when should you use either? Read on.
Dispose()
is used to free up unmanaged resources, not managed resources such as memory.
As such, you should always call Dispose()
either directly or via using
for any type that implements it, unless the type explicitly documents that you don't need to. Do not avoid calling it just because someone tells you that the memory usage might be less.
Incidentally, I'm very dubious about that article on DotNetPearls. It looks like bad advice, and I'm not even sure that the way they measured the memory use is valid.
In answer to your question:
Can you explain me why using increases memory consumption in that example?
Not without trying to reproduce it - but I suspect that the way they measured it is not correct, and the vagaries of garbage collection have yielded misleading results.
Note how the article doesn't state how they measured the memory use, and certainly doesn't give a compilable reproduction. Unless such evidence is provided, I think their reported results should be ignored.
The article's conclusion about what might cause the "increased" memory use is nonsense:
The unneeded using statements ended up wasting memory. This could be explained by the method size bloat and the increased complexity.
If you look at the memory use, it varies from run to run. But "method size bloat and the increased complexity" (tiny though it would be) would cause a constant change in memory usage.
It's apparent that this part of the article should be approached with extreme caution.