internal void Dispose() { // Do we need to check that the library has finished being loaded? // Switch off the living things this.library_index.Dispose(); this.folder_watcher_manager.Dispose(); // Clear the references for sanity's sake this.expedition_manager = null; this.password_manager = null; this.blackwhite_list_manager = null; this.recently_read_manager = null; this.ai_tag_manager = null; this.library_index = null; this.folder_watcher_manager = null; this.library_db = null; }
public Library(WebLibraryDetail web_library_detail) { this.web_library_detail = web_library_detail; Logging.Info("Library basepath is at {0}", LIBRARY_BASE_PATH); Logging.Info("Library document basepath is at {0}", LIBRARY_DOCUMENTS_BASE_PATH); Directory.CreateDirectory(LIBRARY_BASE_PATH); Directory.CreateDirectory(LIBRARY_DOCUMENTS_BASE_PATH); library_db = new LibraryDB(LIBRARY_BASE_PATH); folder_watcher_manager = new FolderWatcherManager(this); library_index = new LibraryIndex(this); ai_tag_manager = new AITagManager(this); recently_read_manager = new RecentlyReadManager(this); blackwhite_list_manager = new BlackWhiteListManager(this); password_manager = new PasswordManager(this); expedition_manager = new ExpeditionManager(this); // Start loading the documents in the background... SafeThreadPool.QueueUserWorkItem(o => BuildFromDocumentRepository()); }
protected virtual void Dispose(bool disposing) { Logging.Debug("Library::Dispose({0}) @{1}", disposing, dispose_count); try { LibraryIsKilled = true; if (dispose_count == 0) { // Get rid of managed resources / get rid of cyclic references: // Do we need to check that the library has finished being loaded? // Switch off the living things library_index?.Dispose(); folder_watcher_manager?.Dispose(); // NULL the memory database Utilities.LockPerfTimer l2_clk = Utilities.LockPerfChecker.Start(); lock (pdf_documents_lock) { l2_clk.LockPerfTimerStop(); pdf_documents.Clear(); pdf_documents = null; } } // Clear the references for sanity's sake expedition_manager = null; password_manager = null; blackwhite_list_manager = null; recently_read_manager = null; ai_tag_manager = null; library_index = null; folder_watcher_manager = null; library_db = null; #if false web_library_detail = null; // cyclic reference as WebLibraryDetail instance reference us, so we MUST nil this one to break the cycle for the GC to work well. #else // cyclic reference as WebLibraryDetail instance reference us, so we MUST nil this one to break the cycle for the GC to work well. // // WARNING: // The most obvious way (see above in `#if false` branch) would be to NULL the weblibdetail reference, but this will cause all sorts of extremely // nasty crashes, including memory corruption, as this reference is accessed in Library background task(s) which might discover that the // library at hand has been killed rather late. // // When those code chunks, e.g. *anything* inside `BuildFromDocumentRepository()`, crash on a NULL dereference of any of the other NULLed // library members, the error resolution code highly depends on a *still working* web_library_detail reference/instance. // To resolve the cyclic reference in there (as the web_lib_detail has a `Library` reference), we hack this by creating a *temporary* // intermediate web_library_detail instance, which is a copy of the original *sans Library reference*. // We DO NOT nuke the Library member in the original web_library_detail as that would cause all sorts of other harm since there's other // code which depends on a certain valid lifetime of that instance and that code should dispose of the record once it is done using it... // // Cloning... web_library_detail = web_library_detail.CloneSansLibraryReference(); #endif } catch (Exception ex) { Logging.Error(ex); } ++dispose_count; }
/***************************************************/ /*** METHODS ************************/ /***************************************************/ /******** UNITY MESSAGES ************************/ // Use this for initialization void Start() { m_expeditionManager = ExpeditionManager.Instance; }
// Constructor public WarManager() : base() { worldCities = new WorldCity(); myExpedition = new ExpeditionManager(); }