I'm rather surprised that there isn't a generic Pool class in the BCL. I've written my own and currently the policy around emptying pool (ie, no objects are being removed from the pool so it should release objects which aren't being used) is based on a timer.
I don't like that fact, but it's the best I could come up with. I was thinking that ideally I could have my pool class base its releasing policy around the frequency of GC collections. The best situation would be registering for an event right before a collect
would occur and then it could release objects which have been in the pool for a while. I can understand why .Net doesn't have that event because someone could really mess up the GC's ability to collect, ever. So the next best thing would be an event that the
pool class could register to which happens at the end of every GC collect. That way the pool could keep track of how my GC collections an object has survived and if it gets past a well studied out limit, it could release the reference to that object.
Since the GC class doesn't have any events, would there be another way to do this?
View Complete Post