public void ObjectIsRemovedFromCollectionOnceNotReachable() { var _0 = new object(); _collection.Add(_0); CallInItsOwnScope(() => { var _1 = new object(); _collection.Add(_1); GC.Collect(); Assert.Equal(2, _collection.Size); Assert.Equal(2, _collection.Count()); }); GC.Collect(); Assert.Equal(2, _collection.Size); Assert.Single(_collection); }
public void Add() { var MyCollection = new WeakCollection <object>(); var MyObject = new object(); MyCollection.Add(MyObject); GC.Collect(); Assert.AreEqual(1, MyCollection.Count(), "Item was not added"); GC.KeepAlive(MyObject); }
public void AddRange() { var MyCollection = new WeakCollection <object>(); var MyObject1 = new object(); var MyObject2 = new object(); MyCollection.AddRange(new object[] { MyObject1, MyObject2 }); GC.Collect(); Assert.AreEqual(2, MyCollection.Count(), "Items were not added"); GC.KeepAlive(MyObject1); GC.KeepAlive(MyObject2); }