Factor out the logic for onlyReadsMemory into a helper function.