C#的内存回收代码
作者:shichen2014 时间:2023-06-20 06:38:47
本文实例讲述了C#的内存回收方法。分享给大家供大家参考。具体实现方法如下:
如下示例代码是调用win32底层操作,可实现内存的回收。
[DllImport("kernel32.dll", EntryPoint = "SetProcessWorkingSetSize")]
public static extern int SetProcessWorkingSetSize(IntPtr process, int minSize, int maxSize);
/// <summary>
/// 释放内存
/// </summary>
public static void ClearMemory()
{
GC.Collect();
GC.WaitForPendingFinalizers();
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
{
SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1);
}
}
希望本文所述对大家的C#程序设计有所帮助。
标签:C#,内存,回收
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
解决Java中socket使用getInputStream()阻塞问题
2022-06-16 14:33:14
C#和vb.net实现PDF 添加可视化和不可见数字签名
2022-08-01 12:49:02
![](https://img.aspxhome.com/file/2023/2/87042_0s.png)
关于C#连接SQL Server时提示用户登录失败的解决方法
2021-10-03 21:21:58
![](https://img.aspxhome.com/file/2023/1/79071_0s.png)
Android 7.0 Nougat不得不知的11项新功能
2021-06-12 22:50:07
java理论基础Stream管道流状态与并行操作
2021-08-31 14:24:07
![](https://img.aspxhome.com/file/2023/6/87206_0s.jpg)
Java 用Prometheus搭建实时监控系统过程详解
2023-09-06 12:07:40
![](https://img.aspxhome.com/file/2023/0/58470_0s.jpg)
Mybatis如何通过接口实现sql执行原理解析
2022-11-30 11:31:26
![](https://img.aspxhome.com/file/2023/0/60480_0s.jpg)
java和c#使用hessian通信的方法
2021-12-12 22:03:46
![](https://img.aspxhome.com/file/2023/7/68497_0s.png)
Gradle的缓存路径修改的四种方法(小结)
2021-11-09 11:05:51
![](https://img.aspxhome.com/file/2023/4/130424_0s.png)
Android 捕获运行时异常详解
2023-12-22 21:16:30
java 查找字符串所在的位置代码
2023-12-22 21:48:17
![](https://img.aspxhome.com/file/2023/0/79820_0s.jpg)
java虚拟机钩子关闭函数addShutdownHook的操作
2021-10-18 00:58:25
![](https://img.aspxhome.com/file/2023/6/61576_0s.jpg)
浅谈用java实现事件驱动机制
2022-07-12 18:06:03
Flutter进阶之实现动画效果(三)
2023-01-26 05:12:49
![](https://img.aspxhome.com/file/2023/8/118968_0s.gif)
AndroidStudio实现微信界面设计
2022-09-16 22:45:40
![](https://img.aspxhome.com/file/2023/5/137535_0s.png)
Android自定义顶部标题栏
2023-02-21 19:03:47
![](https://img.aspxhome.com/file/2023/7/109167_0s.jpg)
磁盘配额的wmi版本(C#)
2022-07-31 17:55:17
InterlliJ IDEA2020新建java web项目找不到Static Web的解决
2022-04-11 19:54:27
![](https://img.aspxhome.com/file/2023/4/110604_0s.png)
BeanDefinitionRegistryPostProcessor如何动态注册Bean到Spring
2023-11-24 12:56:16
![](https://img.aspxhome.com/file/2023/1/59941_0s.jpg)
android 选项卡(TabHost)如何放置在屏幕的底部
2023-07-09 21:19:59