using System;
using System.Diagnostics;
using System.Runtime.InteropServices;

[DllImport("kernel32.dll")]
private static extern bool SetProcessWorkingSetSize(IntPtr process, int minSize, int maxSize);

/// <summary>
/// 即时释放内存
/// </summary>
public static void FlushMemory()
{
GC.Collect();
GC.WaitForPendingFinalizers();
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1);
}

C#即时释放内存的更多相关文章

  1. ARC 没有自动释放内存

    http://www.cnblogs.com/qingche/p/4569833.html 定位了好几天,才发现是打印日志没有即时释放内存,使用intrustment

  2. [CareerCup] 13.9 Aligned Malloc and Free Function 写一对申请和释放内存函数

    13.9 Write an aligned malloc and free function that supports allocating memory such that the memory ...

  3. CentOS7清理yum缓存和释放内存方法

    清理yum缓存 清理yum缓存使用yum clean 命令,yum clean 的参数有headers, packages, metadata, dbcache, plugins, expire-ca ...

  4. 在dll里malloc/new/cvCreate分配内存,在exe里free/Releases释放内存时会出错。

    写了个程序,在DLL中用malloc分配了一块内存,但是在exe程序中释放,结果程序crash,原因就是:其原因可能是堆被损坏,这也说明 TestMySticker.exe 中或它所加载的任何 DLL ...

  5. PHP unset()函数销毁变量 但没有实现释放内存

    <?PHP $a = "hello";$b = &$a;unset( $b );echo $a; // 输出 helloecho $b; // 报错$b = &quo ...

  6. PHP unset销毁变量并释放内存

    PHP的unset()函数用来清除.销毁变量,不用的变量,我们可以用unset()将它销毁.但是某些时候,用unset()却无法达到销毁变量占用的内存!我们先看一个例子: <?php $s=st ...

  7. vector容器删除某些元素且释放内存

    1,size和capacity size: 指目前容器中实际有多少元素,对应的resize(size_type)会在容器尾添加或删除一些元素,来调整容器中实际的内容,使容器达到指定的大小. capac ...

  8. android回收AnimationDrawable动画的每一帧的图片资源,而释放内存

    回收每一帧的图片,释放内存资源 private void tryRecycleAnimationDrawable(AnimationDrawable animationDrawables) { if ...

  9. Linux手动释放内存

    手动释放内存 1.sync将内存中的缓存写入磁盘 2.  to free pagecache, use echo 1 > /proc/sys/vm/drop_caches;       to f ...

随机推荐

  1. php页面编码设置

    php的header来定义一个php页面为utf编码或GBK编码 php页面为utf编码 header("Content-type: text/html; charset=utf-8&quo ...

  2. kafka_2.11-2.1.0测试

    kafka测试启动创建topic ./kafka-topics.sh --create --zookeeper dip005:2181,dip006:2181,dip007 --replication ...

  3. Linux安装配置git

    1.查看git安装版本 git version 2.查看git安装位置 whereis git 3.yum安装git yum install git 4.生成ssh key cd /root/.ssh ...

  4. centos + nginx + php-fpm +mysql的简单配置

    安装前准备 安装约定(这个根据自己习惯,可自行修改) 1.软件源码包我都下载到/usr/local/src这个目录下 2.软件一般都编译安装到/usr/local这个目录下 安装基础库 yum -y ...

  5. appJSON["window"]["navigationBarTextStyle"] 字段需为 black 或 white

    appJSON["window"]["navigationBarTextStyle"] 字段需为 black 或 white     改动成这个就可以了 &qu ...

  6. python 基于机器学习识别验证码

    1.背景    验证码自动识别在模拟登陆上使用的较为广泛,一直有耳闻好多人在使用机器学习来识别验证码,最近因为刚好接触这方面的知识,所以特定研究了一番.发现网上已有很多基于machine learni ...

  7. Barber paradox

    According to Wikipedia, the well known barber paradox states like this: The barber is the "one ...

  8. tensorflow添加层-【老鱼学tensorflow】

    本节主要定义个添加层的函数,在深度学习中是通过创建多层神经网络来实现的,因此添加层的函数会被经常用到: import tensorflow as tf def add_layer(inputs, in ...

  9. 使用Type.MakeGenericType,反射构造泛型类型

    有时我们会有通过反射来动态构造泛型类型的需求,该如何实现呢?举个栗子,比如我们常常定义的泛型委托Func<in T, out TResult>,当T或TResult的类型需要根据程序上下文 ...

  10. Kubernetes国内镜像、下载安装包和拉取gcr.io镜像

    参考:  https://blog.csdn.net/nklinsirui/article/details/80581286