加压GC以放弃清理内存。 [英] Pressuring GC to give up clean up memory.

查看:86
本文介绍了加压GC以放弃清理内存。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序(在线程中引用
news://msnews.microsoft.com:119 / OP ** ... TNGP05.phx.gbl

不会放弃记忆。有几个人说GC不会清理内存,除非被迫这样做(例如系统内存不足)。

所以我写了一个快速的应用程序来狼吞虎咽一次内存100mb,但是我还没看到任何放弃内存的东西(包括其他.NET应用程序)。

我看到提交费用上涨并且经过物理记忆,但是

仍然没有骰子。


我写得不对吗?


使用System;

使用System.Collections.Generic;

使用System.Text;

使用System.Collections;


命名空间ConsoleApplication1

{

class program

{

static void Main(string [ ] args)

{

ArrayList lst = new ArrayList();

int count = 0;


尝试

{

而(真实)

{

count ++;


//分配1 MB

字节[] K =新字节[1024 * 1024];

lst.Add(K);


Console.WriteLine(count);


if(count%100 == 0)

Console.ReadKey();

}

}

catch(例外情况)

{

Console.WriteLine(GC.GetTotalMemory(false).ToStrin g());

Console.WriteLine(ex.ToString());

Console.ReadLine();

throw;

}

}

}

}

I have an app ( referenced in thread
news://msnews.microsoft.com:119/OP**...TNGP05.phx.gbl )
that won''t give up memory. Several people stated that GC won''t clean up
memory unless pressured to do so (e.g. system running out of memory).
So I wrote a quickie app to gobble up memory 100mb at a time, but I
still don''t see anything giving up memory (including other .NET apps).
I see the commit charge going up and go past the physical memory, but
still no dice.

Did I write it correctly?

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
ArrayList lst = new ArrayList();
int count = 0;

try
{
while (true)
{
count++;

// allocate 1 MB
Byte[] K = new byte[1024 * 1024];
lst.Add(K);

Console.WriteLine(count);

if (count % 100 == 0)
Console.ReadKey() ;
}
}
catch (Exception ex)
{
Console.WriteLine(GC.GetTotalMemory(false).ToStrin g());
Console.WriteLine(ex.ToString());
Console.ReadLine();
throw;
}
}
}
}

推荐答案

弗兰克,


您看到的数字是唯一关注的数字,或者你的应用程序消耗的内存是否会对其他应用程序产生可测量的影响

在盒子上?

-

- Nicholas Paldino [.NET / C#MVP]

- mv*@spam.guard .caspershouse.com


" Frank Rizzo" < no ** @no.comwrote in message

news:%2 **************** @ TK2MSFTNGP02.phx.gbl ...
Frank,

Is the number you are seeing the only concern, or is the memory that is
being consumed by your app having a measurable effect on other applications
on the box?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Frank Rizzo" <no**@none.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...

>我有一个应用程序(在线程中引用
news://msnews.microsoft.com:119 / OP ** ... TNGP05.phx。 gbl
不会放弃记忆。有几个人说GC不会清理内存,除非被迫这样做(例如系统内存不足)。所以我写了一个快速应用程序,一次吞噬内存100mb,但我仍然没有看到任何放弃内存的东西(包括其他.NET应用程序)。

我看到提交费用上升并超过了物理内存,但

仍然没有骰子。


我是否写得正确?


使用System;

使用System.Collections.Generic;

使用System.Text;

使用System。收藏;


命名空间ConsoleApplication1

{

class program

{

static void Main(string [] args)

{

ArrayList lst = new ArrayList();

int count = 0;


试试

{

而(真实)

{

count ++;


//分配1 MB

字节[] K =新字节[1024 * 10 24];

lst.Add(K);


Console.WriteLine(count);


if (计数%100 == 0)

Console.ReadKey();

}

}

catch(例外情况ex)

{

Console.WriteLine(GC.GetTotalMemory(false).ToStrin g());

Console.WriteLine(ex .ToString());

Console.ReadLine();

throw;

}

}

}

}
>I have an app ( referenced in thread
news://msnews.microsoft.com:119/OP**...TNGP05.phx.gbl )
that won''t give up memory. Several people stated that GC won''t clean up
memory unless pressured to do so (e.g. system running out of memory). So I
wrote a quickie app to gobble up memory 100mb at a time, but I still don''t
see anything giving up memory (including other .NET apps).
I see the commit charge going up and go past the physical memory, but
still no dice.

Did I write it correctly?

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
ArrayList lst = new ArrayList();
int count = 0;

try
{
while (true)
{
count++;

// allocate 1 MB
Byte[] K = new byte[1024 * 1024];
lst.Add(K);

Console.WriteLine(count);

if (count % 100 == 0)
Console.ReadKey() ;
}
}
catch (Exception ex)
{
Console.WriteLine(GC.GetTotalMemory(false).ToStrin g());
Console.WriteLine(ex.ToString());
Console.ReadLine();
throw;
}
}
}
}



Nicholas Paldino [.NET / C#MVP]写道:
Nicholas Paldino [.NET/C# MVP] wrote:

Frank,


您看到唯一关注的数字,还是内存是
您的应用程序消耗的
对其他应用程序具有可衡量的影响


Frank,

Is the number you are seeing the only concern, or is the memory that is
being consumed by your app having a measurable effect on other applications
on the box?



基本上,决定该应用程序将与SqlServer2k5 64位相同的盒子上的权力,它消耗不合理的金额

的内存(与sqlserver2k相比,无论如何)。所以我的应用程序和/或
SQL Server的总和正在推动物理内存的限制。当它确实越过这个限制时,事情变得非常非常缓慢。当我的应用程序空闲超过一定时间时,我尝试通过将根对象设置为null来转储内存

内容 - 但这似乎不是

有效果。

Basically, the powers that be, decided that the app is going to be on
the same box as the SqlServer2k5 64-bit, which consumes ungodly amounts
of memory (compared to sqlserver2k, anyways). So the sum of my app and
SQL Server is pushing up against the limits of physical memory. When it
does cross that limit, things get really, really slow. When my app is
idle for more than a certain amount of time, I try to dump the memory
contents by setting the root object to null - but that does not seem to
be having an effect.


弗兰克,


远非如此对我来说是挑战权力,但是你的应用程序是否需要依赖于与sql server完全相同的盒子运行?b $ b作为一般的

指南,我不会在不需要

的SQL Server盒子上运行其他任何东西。

-

- Nicholas Paldino [.NET / C#MVP]

- mv *@spam.guard.caspershouse.com


Frank Rizzo < no ** @no.comwrote in message

news:eY ************* @ TK2MSFTNGP05.phx.gbl ...
Frank,

Far be it for me to challenge the powers that be, but is your app
dependent on running on the same exact box as sql server? As a general
guideline, I don''t run ANYTHING else on SQL Server boxes that doesn''t need
to be there.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Frank Rizzo" <no**@none.comwrote in message
news:eY*************@TK2MSFTNGP05.phx.gbl...

Nicholas Paldino [.NET / C#MVP]写道:
Nicholas Paldino [.NET/C# MVP] wrote:

> Frank,

是您看到唯一关注的数字,或者您的应用程序正在消耗的内存对盒子上的其他应用程序产生可测量的影响?
>Frank,

Is the number you are seeing the only concern, or is the memory that
is being consumed by your app having a measurable effect on other
applications on the box?



基本上,权力决定了应用程序将与SqlServer2k5 64位的

相同的框一样,它消耗了不计其数的内存(与sqlserver2k相比,无论如何)。所以我的应用程序和SQL的总和

服务器正在推动物理内存的限制。当它超过这个限制时,事情变得非常非常缓慢。当我的应用程序空闲时间超过一定时间后,我会尝试通过将根对象设置为null来转储内存内容 - 但这似乎不是获得

效果。


Basically, the powers that be, decided that the app is going to be on the
same box as the SqlServer2k5 64-bit, which consumes ungodly amounts of
memory (compared to sqlserver2k, anyways). So the sum of my app and SQL
Server is pushing up against the limits of physical memory. When it does
cross that limit, things get really, really slow. When my app is idle for
more than a certain amount of time, I try to dump the memory contents by
setting the root object to null - but that does not seem to be having an
effect.



这篇关于加压GC以放弃清理内存。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆