package com; import com.Struct.MEMORYSTATUS; /** * @author ╱―★神★―╲ * @name 内存优化 */ public class Ncyh { public static double execute() { int[] pids = new int[1024]; int[] retLen = new int[1]; //枚举进程 Win32.Psapi.EnumProcesses(pids, 1024 * 4 ,retLen); System.out.println("当前进程数 = " + retLen[0] / 4); MEMORYSTATUS ms = new MEMORYSTATUS(); Win32.Kernel32.GlobalMemoryStatus(ms); // k = 所有进程所占用的内存大小 int k = ms.dwTotalPhys - ms.dwAvailPhys; // 遍历每一个进程,进行内存释放 for(int i=0;i< retLen[0] / 4 ; i++) { int hProcess = Win32.Kernel32.OpenProcess(2035711, false,pids[i]); Win32.Kernel32.SetProcessWorkingSetSize(hProcess, -1, -1); Win32.Kernel32.CloseHandle(hProcess); } Win32.Kernel32.GlobalMemoryStatus(ms); // 释放前的内存 减去 释放后的内存。计算本次释放了多少内存 double rDb = (k - (ms.dwTotalPhys - ms.dwAvailPhys))/1024.0/1024.0 ; return Math.round( rDb * 100 ) / 100.0; } public static void main(String[] args) { System.out.println( "本次释放内存 = " + Ncyh.execute() +" MB"); } }

skd666 LV8
2021年11月21日
何松林 LV7
2021年4月20日
1342203642 LV10
2020年9月1日
yuanfen LV16
2020年8月26日
zaq123zaq LV10
2019年11月26日
blueskyroof LV9
2019年9月20日
zxx521125 LV9
2019年8月26日
blackempty LV2
2019年6月19日
爱情的本质 LV16
2019年1月22日
1084256721 LV2
2018年11月30日

gao8970206 LV2
2023年12月20日
Seaskye LV14
2023年11月2日
微信网友_6489792788402176
2023年5月24日
暂无贡献等级
二进制2 LV3
2023年1月6日
爱情戴罪的羔羊 LV7
2022年9月17日
crosa_Don LV18
2022年7月20日
ZZF515515
2022年6月23日
暂无贡献等级
a3870764722a LV22
2021年12月28日
xptbxptb LV1
2021年12月11日
zs131420 LV1
2021年11月29日