如何立即回收内存C#
2024-10-21 05:02:21
C#如何立即回收内存
1.把对象赋值为null
2.立即调用GC.Collect();
注意:这个也只是强制垃圾回收器去回收,但具体什么时候执行不确定。
代码:
[System.Runtime.InteropServices.DllImportAttribute("kernel32.dll", EntryPoint = "SetProcessWorkingSetSize", ExactSpelling = true, CharSet =System.Runtime.InteropServices.CharSet.Ansi, SetLastError = true)]
private static extern int SetProcessWorkingSetSize(IntPtr process, int minimumWorkingSetSize, int maximumWorkingSetSize); #region 内存回收
public void ClearMemory()
{
GC.Collect();
GC.SuppressFinalize(this); if (Environment.OSVersion.Platform == PlatformID.Win32NT)
{
SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -, -);
}
}
#endregion ClearMemory();
https://blog.csdn.net/xwnxwn/article/details/78009071
最新文章
- 初识Jsoup之解析HTML
- php 复习
- HDU 2444 The Accomodation of Students (偶图判定,匈牙利算法)
- CF Exam (数学)
- 使用开源的PullToRefreshScrollView scrollTo和scrollby遇到的问题
- 对TMemoryStream的一些改进(用到了LockFile)
- java中的传值
- Apache 隐藏入口文件 index.php
- javaScript基础概念小知识点集
- Node编码规范
- java8新特性-默认方法
- wordpress中安装插件需要ftp服务
- ICML 2018 | 从强化学习到生成模型:40篇值得一读的论文
- Java基础知识点(三)
- Spring 依赖注入优化
- 性能测试day05_Jmeter学习
- 批量部署ssh私钥认证
- centos 最小化安装后要做的事情
- git配置文件
- Unable to update index for central http://repo1.maven.org/maven2/ 解决方法
热门文章
- Beta冲刺(1/7)——2019.5.22
- DT6.0开发之-调用信息评论
- 如何使用project制定项目计划?(附详细步骤截图)
- Combined beamformers for robust broadband regularized superdirective beamforming
- Linux CentOS7 字符集
- CentOS yum repo
- Dart和JavaScript对比小结
- 微信小程序class封装http
- 使用docker 基于centos7制作mysql镜像
- (五)Cisco dhcp snooping实例3-多交换机环境(DHCP服务器和DHCP客户端位于同VLAN)