Putting peoples opinions about garbage collection aside are there any deadlocking issues with the following:
private static readonly object lockObj = new object();
lock(lockObj )
{
///Load objects into a cache List<object> from DB call
GC.Collect(2);
GC.WaitForPendingFinalizers();
GC.Collect(2);
}
Major edit, so comments may seem out of place. Sorry for the inconvenience.
It is hard to tell for sure.
Assuming the code looks something like this
You could get a deadlock if you had more instances of
SomeTypeas they all share a static object for locking. You need to have at least one unrooted and uncollected instance ofSomeTypeand callFooon another instance.Now, if you don’t have the finalizer as above, I can’t see how the code could deadlock.