summaryrefslogtreecommitdiff
path: root/tests/src/GC/API/GC/TotalMemory.cs
blob: d6233b1c8c374079e1fa3fffff2ef09f1e42f8ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

// Tests GC.TotalMemory

using System;

public class Test {

    public static int Main() {

        GC.Collect();
        GC.Collect();

        int[] array1 = new int[20000];
        int memold = (int) GC.GetTotalMemory(false);
        Console.WriteLine("Total Memory: " + memold);
        
        array1=null;
        GC.Collect();
        
        int[] array2 = new int[40000];
        int memnew = (int) GC.GetTotalMemory(false);
        Console.WriteLine("Total Memory: " + memnew);
        GC.KeepAlive(array2);

        if(memnew >= memold) {
            Console.WriteLine("Test for GC.TotalMemory passed!");
            return 100;
        }
        else {
            Console.WriteLine("Test for GC.TotalMemory failed!");
            return 1;
        }
    }
}