Exemplo n.º 1
0
        //COR-1839
#if !SILVERLIGHT
        /// <exception cref="System.Exception"></exception>
        public virtual void Test()
        {
            if (!Platform4.HasWeakReferences())
            {
                return;
            }
            var item = new Item
                           ();

            Store(item);
            Commit();
            var reference = new ByRef();

            ReferenceSystem().TraverseReferences(new _IVisitor4_30(reference));
            Assert.IsNotNull(((ObjectReference)reference.value));
            item = null;
            long timeout   = 10000;
            var  startTime = Runtime.CurrentTimeMillis();

            while (true)
            {
                var currentTime = Runtime.CurrentTimeMillis();
                if (currentTime - startTime >= timeout)
                {
                    Assert.Fail("Timeout waiting for WeakReference collection.");
                }
                Runtime.Gc();
                Runtime.RunFinalization();
                Thread.Sleep(1);
                if (((ObjectReference)reference.value).GetObject() == null)
                {
                    break;
                }
            }
            startTime = Runtime.CurrentTimeMillis();
            while (true)
            {
                var currentTime = Runtime.CurrentTimeMillis();
                if (currentTime - startTime >= timeout)
                {
                    Assert.Fail("Timeout waiting for removal of ObjectReference from ReferenceSystem."
                                );
                }
                var found = new BooleanByRef();
                ReferenceSystem().TraverseReferences(new _IVisitor4_63(reference, found));
                if (!found.value)
                {
                    return;
                }
                Thread.Sleep(10);
            }
        }
Exemplo n.º 2
0
 public static IWeakReferenceSupport ForObjectContainer(ObjectContainerBase container
                                                        )
 {
     if (!Platform4.HasWeakReferences())
     {
         return(DisabledWeakReferenceSupport());
     }
     if (!container.ConfigImpl.WeakReferences())
     {
         return(DisabledWeakReferenceSupport());
     }
     return(new EnabledWeakReferenceSupport(container));
 }