There are 3 options you can look at to try to prevent the out of memory errors.
1) Do any of your records have large BLOB or Text fields, and if so, do you need these for your processing ? If not, they can be excluded from the fetch using the Include/Exclude fields functionality.
2) You can look at using paging to allow you to process the data in batches.
3) Does the data need to be fetched as entities? Could it instead be fetched as a typed/dynamic list? There is a significant memory overhead in using entities.
Matt