110,534
社区成员
发帖
与我相关
我的任务
分享
1 using System.Data;
2 public void MemoryTracking()
3 {
4 try
5 {
6 for (int i = 0; i < 100; i ++)
7 {
8 DataTable dt = new DataTable();
9 fillTable(dt);
10
11 dt.Dispose();
12 dt = null;
13 }
14 }
15 catch(Exception ex)
16 {
17 throw (ex);
18 }
19 }
private void fillTable(DataTable dt)
{
// 为 dt 创建10列,5000 条有数据的 DataRow
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WinceTestProject01
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
MEMORYSTATUS mem1, mem2;
private void button1_Click(object sender, EventArgs e)
{
GlobalMemoryStatus(ref mem1);
Form2 frm = new Form2();
frm.ShowDialog();
frm.Dispose();
frm = null;
GC.Collect();
GlobalMemoryStatus(ref mem2);
MessageBox.Show(
(mem1.dwAvailPhys ).ToString() +
"\r\n" +
(mem2.dwAvailPhys ).ToString()
);
}
[StructLayout(LayoutKind.Sequential)]
public struct MEMORYSTATUS
{
public int dwLength;
public int dwMemoryLoad;
public int dwTotalPhys;
public int dwAvailPhys;
public int dwTotalPageFile;
public int dwAvailPageFile;
public int dwTotalVirtual;
public int dwAvailVirtual;
}
[DllImport("coredll.dll", EntryPoint = "GlobalMemoryStatus")]
public static extern void GlobalMemoryStatus(
ref MEMORYSTATUS lpBuffer
);
}