Пример #1
0
        /// <summary>
        /// Perform an action, checking the system's memory usage before and after.
        /// </summary>
        /// <param name="action">The action to perform.</param>
        private static void CheckMemoryUsage(Action action)
        {
            RunGarbageCollection();
            long memoryAtStart          = EseInteropTestHelper.GCGetTotalMemory(true);
            int  collectionCountAtStart = EseInteropTestHelper.GCCollectionCount(0);

            action();

            int collectionCountAtEnd = EseInteropTestHelper.GCCollectionCount(0);

            RunGarbageCollection();
            long memoryAtEnd = EseInteropTestHelper.GCGetTotalMemory(true);

            EseInteropTestHelper.ConsoleWriteLine(
                "Memory changed by {0:N} bytes ({1} GC cycles)",
                memoryAtEnd - memoryAtStart,
                collectionCountAtEnd - collectionCountAtStart);
        }