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

最新文章

  1. 初识Jsoup之解析HTML
  2. php 复习
  3. HDU 2444 The Accomodation of Students (偶图判定,匈牙利算法)
  4. CF Exam (数学)
  5. 使用开源的PullToRefreshScrollView scrollTo和scrollby遇到的问题
  6. 对TMemoryStream的一些改进(用到了LockFile)
  7. java中的传值
  8. Apache 隐藏入口文件 index.php
  9. javaScript基础概念小知识点集
  10. Node编码规范
  11. java8新特性-默认方法
  12. wordpress中安装插件需要ftp服务
  13. ICML 2018 | 从强化学习到生成模型:40篇值得一读的论文
  14. Java基础知识点(三)
  15. Spring 依赖注入优化
  16. 性能测试day05_Jmeter学习
  17. 批量部署ssh私钥认证
  18. centos 最小化安装后要做的事情
  19. git配置文件
  20. Unable to update index for central http://repo1.maven.org/maven2/ 解决方法

热门文章

  1. Beta冲刺(1/7)——2019.5.22
  2. DT6.0开发之-调用信息评论
  3. 如何使用project制定项目计划?(附详细步骤截图)
  4. Combined beamformers for robust broadband regularized superdirective beamforming
  5. Linux CentOS7 字符集
  6. CentOS yum repo
  7. Dart和JavaScript对比小结
  8. 微信小程序class封装http
  9. 使用docker 基于centos7制作mysql镜像
  10. (五)Cisco dhcp snooping实例3-多交换机环境(DHCP服务器和DHCP客户端位于同VLAN)