Memory leak in Strategy Test

Posted By: pascalx

Memory leak in Strategy Test - 09/06/17 11:46

I get Error 060: Memory fragmented / limit exceeded regularly when testing a few strategies. Zorro can have a strategy that, let's say, allocates 800 MB in one test run. Now if you happen to run 3 other strategies afterwards with 800 MB each too, then you already crash Zorro. There is no memory cleanup after a test run, so it just takes a few scripts to exceed the memory limit.

Consider this script and create 4 instances of it. Use the Zorro M1 history data. Run each script once. Zorro will run out of memory.

Code:
void run()
{
	set(TICKS);
	NumYears = 10;
	string currentAsset;
	while(currentAsset=loop("EUR/USD", "XAU/USD", "USD/JPY", "USD/CAD", "GBP/USD", "AUD/USD", "NAS100", "SPX500"))
		asset(currentAsset);
}



The expectation is that Zorro cleans up after a test run. There is only a cleanup if you retest a strategy.

Summary:
Hit "Test" once, hit "Test" again -> memory cleans up.
Hit "Test" once, change strategy, hit "Test again -> no memory clean up

Attached picture error.png
Posted By: AndrewAMD

Re: Memory leak in Strategy Test - 09/06/17 17:24

Can confirm. I have repeated this error in Zorro S 1.61.6, having compiled this strategy in DLL form (attached).


Description: bug001.dll
Attached File
bug001.dll.zip  (267 downloads)
Posted By: jcl

Re: Memory leak in Strategy Test - 09/07/17 11:55

That's mentioned in the manual. There is no "clean up". It's no leak, but simply fragmented memory. You must restart. No way around. It does not matter if your strategy is C or DLL.
Posted By: pascalx

Re: Memory leak in Strategy Test - 09/07/17 13:36

But that is a flaw in the programs memory design, isn't it? After all, only the program logic is responsible for storing data on the heap. If the allocator(s) don't organize the given data according to their lifetime, then you end up with fragmentation. But given that a test run has a known lifetime, it should be very well possible to organize the allocations serving that specific test run appropriately.
Posted By: jcl

Re: Memory leak in Strategy Test - 09/07/17 14:45

A fixed memory allocation order could indeed overcome fragmentation. But this is extremely hard to implement, if possible at all, and would probably require a large amount of reallocation at runtime with all the negative consequences on speed. This is not planned at this point.
Posted By: pascalx

Re: Memory leak in Strategy Test - 09/07/17 15:57

Considering this company is developing a game engine I would assume it has appropriate bucket allocators to perform this task. If the engine unloads a game level it also cleans up its contents without crashing the game after a few level loads, right?
Posted By: jcl

Re: Memory leak in Strategy Test - 09/08/17 07:37

Indeed. I had not thought about that. The Acknex engine uses a special preallocated memory management for avoiding that the game runs out of memory at level change. This would probably solve the fragmentation problem. I`ve made a notice to consider this for a future update.
Posted By: pascalx

Re: Memory leak in Strategy Test - 09/08/17 14:24

Thanks bro.
© 2024 lite-C Forums