[Mono-dev] issue with testing dispose code
Bas Smit
basjsmit at gmail.com
Sun Mar 1 07:59:40 EST 2009
Hi guys,
Im looking at Mono Ninject2 compatibility and Ive come across a problem.
Nate has a bunch of tests to check his dispose code (example below). For
this purpose we need a way to force disposing of unused objects. Currently
the tests use GC.Collect() for that, however on mono that doesnt necessarily
mean that unused objects are disposed of. Is there a way to force the GC to
dispose of all unused objects?
Regards, Bas
Here is an example of such a (xunit) test:
[Fact]
public void
InstancesActivatedWithinScopeAreDeactivatedAfterThreadIsGarbageCollectedAndCacheIsPruned()
{
kernel.Bind<NotifiesWhenDisposed>().ToSelf().InThreadScope();
var cache = kernel.Components.Get<ICache>();
NotifiesWhenDisposed instance = null;
ThreadStart callback = () => instance =
kernel.Get<NotifiesWhenDisposed>();
var thread = new Thread(callback);
thread.Start();
thread.Join();
thread = null;
GC.Collect();
GC.WaitForPendingFinalizers();
cache.Prune();
instance.ShouldNotBeNull();
instance.IsDisposed.ShouldBeTrue();
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20090301/f382e522/attachment.html
More information about the Mono-devel-list
mailing list