I have the following code in an object pool that implements the IEnumerable interface.
public IEnumerable ActiveNodes
{
get
{
for (int i
Dont be afraid of those tiny garbage objects. The ActiveNodes in the pool will (should) be much more costly. Therefore, if you get rid of recreating them it should be sufficient.
@Edit: if you are made to use a managed platform and really want to archieve a zero-garbage state, disclaim the usage of the pool in a foreach loop and iterate over it in another manner, possibly utilizing an indexer. Or consider creating a list of potential nodes and return that instead.
@Edit2: Of course, implementing IEnumerator und using Current(), Next() and so on, would work as well.