Linq allows you to create new object inside of a query expression. This is useful when you have classes that encapsulate generation of a list. I’m wondering how you dispose of objects that are created that need it?
Example:
class Generator
{
public IEnumerable<int> Gen(int size)
{
return Enumerable.Range(0, size);
}
}
class bar
{
public void doit()
{
var foo =
from r in Enumerable.Range(1, 3)
from g in new Generator().Gen(r)
select g;
}
}
This will create 3 Generator objects that will be garbage collected at some point. If Generator was IDisposable how would I get the Dispose() call?