How would you optimize this specific code snippet for memory usage?
Implement a function optimize_memory(nums) that returns the sum of all integers in nums using the least extra memory possible. The input is a list of integers, and the output is a single integer sum.
def optimize_memory(nums):