GC checkpoint
Challenge on lesson: Checkpoint: GC and memory
CHALLENGE
Difficulty: advanced+25 XP
Implement static long MeasureAlloc<T>(Func<T> factory, int iterations) returning GC.GetAllocatedBytesForCurrentThread() delta across iterations calls of factory โ the standard micro-allocation probe. Then implement static int Gen0Collections() returning GC.CollectionCount(0), and static WeakReference MakeWeak() returning a WeakReference to a freshly allocated object(). The test: 1000 iterations of new byte[64] must allocate MORE than 1000*64 bytes; a weak reference's Target must become null after GC.Collect + WaitForPendingFinalizers + GC.Collect (the helper-method liveness pattern the lesson teaches).
Press Submit to check your solution.
Back to lesson: Checkpoint: GC and memory