Out of memory means, the data needs more memory that you have. This has nothing to do with loops, you must make do with the 2 GB limit per win32 process. You can not load unlimited amounts of price data.