I agree with Ben Lessani that you should use the core/iterator resource model to load big collections one row at a time if possible.
However, there are limitations. As explained in "addAttributeToSelect not working with core/resource_iterator?" it does not work well with EAV models if you need to include values from the attribute value tables.
And the linked example from StackOverflow is actually not that good because it repeats the same query with different LIMIT expressions. For complex queries this might be a performance problem, but even more important, you will get duplicates if new rows are added in between.
A better way to handle collections in chunks is to first load all the ids, then use these ids as a filter for the actual paged collection.
Simple example for products:
$ids = Mage::getModel('catalog/product')
->getCollection()
->getAllIds();
$page = 1;
do {
$collection = Mage::getModel('catalog/product')
->getCollection()
->addIdFilter($ids)
->setPageSize(100)
->setCurPage($page);
$results = $collection->load();
// do stuff ......
$page++;
} while ($results->count());
core/resource_iteratorsolution actually doesn't paginate the mysql query. It loads the entire result set at once, but then it gives you a row at a time to deal with in your PHP code. So it does avoid memory faults within PHP, but at some point it will trigger mysql max packet sizes, if the result set is very large. I think I'm going to try and build out a nice abstract chunked resource_iterator usingsetPageSize()– kalenjordan Apr 26 '13 at 16:20