How to dispose Objects correctly in cAlgo
How to dispose Objects correctly in cAlgo
12 Jun 2017, 15:56
Hi all,
I am working on a Bot that contains different 'Strategies' to be able to react to different market situations.
Basically if a signal to execute a strategy is thrown by the directing method a new corresponding strategyobject is initialized and executes the individual strategylogic. Works fine so far, but I keep running into problems with garbage collection.
If the algo is running over long periods of time multiple strategy object are initialized and since they contain indicators, dictionaries an so on they seem to lead cAlgo into a deadlock.
As of now I am trying to face the issue in implementing :iDisposable in the strategies and in strategy.Dispose() I 'null' all created objects to make way for the garbage collector.
StrategyBluePrintClass { public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } internal virtual void Dispose(bool disposing) { if (_disposed) { return; } if (disposing) { // free other managed objects that implement IDisposable only } // release any unmanaged objects CBot = null; Account = null; TradedSymbol = null; Timer = null; Director = null; LogWriter = null; WatchDog = null; OpeningSignal = null; TradeOperations = null; _disposed = true; } } SpecificStrategyClass { internal override void Dispose(bool disposing) { base.Dispose(disposing); _iATR_3 = null; _iBolBand_20_2_Exp = null; _iParaSAR_0j01_0j3 = null; _iRSI_14 = null; } }
Since I am still experimenting sometimes an object link, for example an inidcator still may be active in the strategyobject after it has finished its trading logic, and hence does let it being garbage collected :(
Is there an 'easier' or more important 'secure' way to safely kill an object in C#? Or does cAlgo feature any Method that terminates alle active connections between the cAlgo mainframe an the running cBot???
appreciate any help
cheers
Mikro
Mikro
12 Jun 2017, 16:37
Since I am still experimenting sometimes an object link, for example an inidcator, still may be active in the strategyobject after it has finished its trading logic, and hence dosn't let it be garbage collected :(
Typing error...
@Mikro