gc.cs
来自「c#的学习资料 书上的东西 很难找到的啊」· CS 代码 · 共 37 行
CS
37 行
//
// gc.cs -- Demonstrates forced garbage collection
//
// Compile this program with the following command line:
// C:>csc gc.cs
//
namespace nsGarbage
{
using System;
using System.Threading;
class clsMain
{
static public void Main ()
{
long Mem = GC.GetTotalMemory (false);
Console.WriteLine ("Beginning allocated memory is " + Mem);
for (int x = 0; x < 10000; ++x)
{
clsClass howdy = new clsClass();
}
Mem = GC.GetTotalMemory (false);
Console.WriteLine ("Allocated memory before garbage collection is " + Mem);
GC.Collect ();
Mem = GC.GetTotalMemory (true);
Console.WriteLine ("Allocated memory after garbage collection is " + Mem);
}
}
class clsClass
{
public clsClass () { }
public int x = 42;
public float f = 2E10f;
public double d = 3.14159;
public string str = "This here's a string";
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?