コード例 #1
0
ファイル: FutureFactory.cs プロジェクト: cmqd/coflows-quant
        public void CleanFuturesFromMemory(DateTime date)
        {
            lock (cleanObjLock)
            {
                List <Future> remove = new List <Future>();
                foreach (Future f in _futureIdDB.Values)
                {
                    if (f.LastTradeDate < date)
                    {
                        remove.Add(f);
                    }
                }

                DateTime[] dts = _currentFutureDB.Keys.ToArray();

                foreach (DateTime dt in dts)
                {
                    if (dt <= date)
                    {
                        Future[] cfs = _currentFutureDB[dt].Values.ToArray();
                        foreach (Future cf in cfs)
                        {
                            Instrument.CleanMemory(cf);
                            Security.CleanMemory(cf);

                            cf.NextFuture.PreviousFuture = null;

                            Instrument und = cf.Underlying;
                            if (_currentFutureDB[dt].ContainsKey(und.ID))
                            {
                                _mainTables[_currentFutureDB[dt][und.ID].ID] = null;
                                _currentFutureDB[dt][und.ID] = null;
                                _currentFutureDB[dt].Remove(und.ID);
                            }
                        }

                        _currentFutureDB[dt] = null;
                        _currentFutureDB.Remove(dt);
                    }
                }

                foreach (Future f in remove)
                {
                    Instrument.CleanMemory(f);
                    Security.CleanMemory(f);

                    if (_futureIdDB.ContainsKey(f.ID))
                    {
                        _mainTables[f.ID] = null;
                        _futureIdDB[f.ID] = null;
                        _futureIdDB.Remove(f.ID);
                    }
                }
            }
        }