I like to conserve the use of dataseries when writing script and make use of the following form quite a bit:
CODE:
Please log in to see this code.
I've puposely exaggerated the iteration count to keep the code simple and illustrate the out of memory error. The iteration count only has to be like 10 or 20 in longer more complex code (1000+ lines).
I have 2 Gb of memory on my system which in not large but not small.
Any ideas why this form causes such a problem?
When the out of memory exception occurs, the only way to solve the problem is to close WealthLab and restart. Just closing the offending strategy window does not release the memory as seen in Task Manager (windows XP Pro).
Size:
Color:
You're creating and caching 10000 new DataSeries, so that eats up your memory.
If you need 10000 DataSeries in a script, buy a ton of memory for a 64-bit computer, and install the 64-bit version of WLP/D.
Size:
Color:
Considering that memory becomes fragmented, there's an operating system with its needs, other applications running in the background, and the fact that the memory limit for an app is 1.3 Gb, 2 gigabytes is not large, that's true.
Let's take the calculator and refresh our knowledge of a formula given here:
Out of memory problems:
54 bytes * number of symbols * number of bars * 10000 DataSeries (yes, your code is summing up data series until they create a real big one)
QUOTE:
When the out of memory exception occurs, the only way to solve the problem is to close WealthLab and restart.
Right, GC (garbage collector) in .NET 2.0 is somewhat lazy (but they improved it in 4.0).
Size:
Color:
Ok, I guess I don't really understand how the dataseries work. I assumed there were only two dataseries in this code and one of them, oom0, was constantly being overwritten.
If this were an array instead of a dataseries in straightup C# code, would it still be creating 10000 new arrays? Somehow I don't think so.
Thanks for the insight.
Size:
Color:
Well, it's straight C# code, but Wealth-Lab (and probably every trading platform) caches DataSeries so that you can access their values later in the script. That "+" sign is an overloaded operator when you use them for DataSeries. Whenever you do that, a new DataSeries is formed and cached. In your example, you're not creating a reference that you can use to access all those interim DataSeries, but you could do that if you wanted.
You can change values of DataSeries elements using the [] accessor. This doesn't drive up memory use.
Size:
Color:
Ok. The earlier comment made me realize that the explicit reference to individual values, the [] element reference, was probably the best way around the build up of caching these dataseries. I'm assuming that when [] is used, then one is really overwriting the memory location and not creating new storage space.
CODE:
Please log in to see this code.
This form of the code works fine with no memory error.
Thanks to all for the feedback.
Size:
Color: