Refer to Memory Usage information located at the following URL:
Specifically to the sections:
1. Strategies for Efficient Use of Memory
2. Resolving "Out of Memory" Errors
The links above go over several methods that may be used to avoid "out-of-memory" errors. Specifically, they cover how to utilize memory allocation and several memory management commands that can be used to make code more memory efficient.
