/// <summary> /// Decrements the root count of the object at the pointer by 1 /// </summary> /// <param name="aPtr"></param> public static unsafe void DecRootCount(ushort *aPtr) { if (RAT.GetPageType(aPtr) != 0) { var rootCount = *(aPtr - 1) >> 1; // lowest bit is used to set if hit *(aPtr - 1) = (ushort)((rootCount - 1) << 1); // loest bit can be zero since we shouldnt be doing this while gc is collecting } }
private unsafe void TestGarbageCollectorMethods() { // allocating + freeing works on gc side int allocated = HeapSmall.GetAllocatedObjectCount(); object c = new object(); int nowAllocated = HeapSmall.GetAllocatedObjectCount(); GCImplementation.Free(c); int afterFree = HeapSmall.GetAllocatedObjectCount(); Assert.AreEqual(allocated + 1, nowAllocated, "NewObj causes one object to be allocated"); Assert.AreEqual(allocated, afterFree, "Free causes one object to be freed again"); var testString = "asd"; Assert.AreEqual(RAT.PageType.Empty, RAT.GetPageType(GCImplementation.GetPointer(testString)), "String is created statically and not managed by GC"); Assert.IsTrue(Heap.Collect() >= 0, "Running GC Collect first time does not crash and returns non-negative value"); }