SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Tue May 21, 2019 5:39 pm

All times are UTC + 3 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Memory Leak
PostPosted: Sat Nov 05, 2011 11:13 pm 
Offline

Joined: Wed Jun 22, 2011 7:37 pm
Posts: 22
I'm seeing a pretty dramatic memory leak in my current strategy (see attached screenshot). When I run the same strategy with simulation engine on the same symbols for the same bars with the same parameters, the memory allocated just goes up and up. I haven't been hitting OutOfMemory errors mainly because I have plenty of memory and have been restarting frequently.

My strategy could be somewhat of a memory hog (involves calculating ratios between pairs and maintaining lists/dictionaries) but my expectation is that the memory committed would more or less return to the same base point each simulation.

Any manual garbage collection that's helpful? Any settings to know about? I'm on 3.2.0 x64, windows 7 Professional system


Attachments:
memoryLeak.PNG
memoryLeak.PNG [ 57.41 KiB | Viewed 5673 times ]
Top
 Profile  
 
 Post subject: Re: Memory Leak
PostPosted: Sun Nov 06, 2011 8:39 am 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6812
Hi,

you can try to add GC.Collect in OnStrtegyStop to see if this is a memory leak or the grabage collector just waits until your strategy will eat up enough memory.

On the other hand it's quite possible that some objects are not garbage collected in your strategy. For example you can manually subscribe to some events and forget to unsubscribe in OnStrategyStop.

Just try to comment our everything in your strategy and check that memory usage goes flat and then start uncommenting things to see which part of your logic produces this king of memory consumption graph.

Regards,
Anton


Top
 Profile  
 
 Post subject: Re: Memory Leak
PostPosted: Mon Nov 07, 2011 2:14 am 
Offline

Joined: Wed Jun 22, 2011 7:37 pm
Posts: 22
Thanks for the ideas. I've tried GC.collect() to no effect, but will step thru the code and see what is causing the leak. I instantiate lots of static objects, anything in particular that is best practice to handle in the OnStrategyStop? Once I find the culprit, how can I release the memory?


Top
 Profile  
 
 Post subject: Re: Memory Leak
PostPosted: Tue Nov 15, 2011 4:58 am 
Offline

Joined: Wed Jun 22, 2011 7:37 pm
Posts: 22
Still troubleshooting this one, but are there any things I should be doing at the end of a backtest in OnStrategyStop?

the strategy design heavily relies on static variables (200+ instruments being analyzed, sorted, traded) so I'm wondering if there's something related to that.


Top
 Profile  
 
 Post subject: Re: Memory Leak
PostPosted: Tue Nov 15, 2011 10:08 am 
Offline
Site Admin

Joined: Thu Jul 17, 2003 10:39 am
Posts: 1478
Hi,

Its hard to find a reason of memory leaks in this situation.
The most probable reason is the strategy code allocates memory for some purposes and does not release it. Is it possible to look into your code?

Regards,
Alex

_________________
SmartQuant Development Team


Top
 Profile  
 
 Post subject: Re: Memory Leak
PostPosted: Fri Dec 09, 2011 1:21 pm 
Offline

Joined: Wed Aug 24, 2011 7:11 pm
Posts: 42
Static variables will stay around for the lifetime of the application. You could try manually clearing all lists, dictionaries and nulling static variable references before forcing a GC.Collect().

Its better to use instance variables if you can. Even so you rely on the Strategy class getting collected so nulling/clearing all can help. To make sure the collection really does collect, try this:

GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 3 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group