Using generators for template output went very badly the last time we
tried it. There were all sorts of unexpected side-effects because
template rendering involves database accesses a lot of the time (due to
lazy evaluation of querysets).
This type of memory usage hit for querysets that are only going to be
used exactly once is something I've been thinking about a bit over the
past few months. There's a case for some kind of "don't cache in memory"
attribute on querysets so that __iter__ won't populate the internal
cache. It's usually going to be far more dangerous than useful, but in
some situations it will be promising. When we branch off from 1.0.x and
trunk can take features again, I'll probably add something along those
lines.
More specifically for your case, though, in a way that won't require
changing anything in core (and it on becomes a django-users type of
problem): try subclassing the GenericSitemap class and replace the
items() method to return a subclass of QuerySet with an overridden
__iter__ that doesn't cache the results in memory. So, you're going to
write something like this:
SkinnyQueryset(QuerySet):
def __iter__(self):
.... # <-- your stuff here
LessGenericSitemap(GenericSitemap):
def items():
# <-- return QuerySet subclass here.
I've left the details up to you, since it's just a matter of looking at
the existing code.
Regards,
Malcolm