.NET managing a cache of self maintaining objects - disposal issue?
Posted on 2015-01-23
In my asp .net environment I have a collectionbase of a proprietary class, each of which represents a set of data for a period. e.g Quarter-To-Date, Yesterday, Today etc.
when the site is started, each class is added to an application scope collectionbase which handles queries by date range such that if a user requests dates which match one of these often requested date ranges the set of data concerns is pulled from the collectionbase in the form of the proprietary class else it is prepared on an ad hoc basis.
Each class contains a system.timer.timers object in order to allow it to check for changes in the underlying data every so often.
The collection base itself also runs a system.timer.timers object which ensures that at midnight the date ranges themselves are reset as 'Yesterday','Today' etc become different dates, so the collectionbase is dropped using me.clear and the proprietary classes are recreated and added back in.
My problem is that the collectionbase members despite having been cleared carry on living, with the timers inside triggering causing the class to carry on requerying the database meaning as each day passes I have more and more objects which I had assumed because they cannot be referenced because I have cleared the collectionbase would have been disposed of.
Is the use of timers a cause of the objects inability to die or is there something else I am missing about the way in which collectionbases and their members are disposed of when me.clear is used?
Thank you for your input.