内存使用异常与异步服务器应用程序

编程入门 行业动态 更新时间:2024-10-06 18:32:38
本文介绍了内存使用异常与异步服务器应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的服务器应用程序中存在一个奇怪的内存问题。这个 应用程序接受套接字连接,传递消息,然后 关闭它们。 使用scitech的.NET内存分析器,它报告合理的内存行为,在实时字节上徘徊在400k左右,并且对于所使用的总字节,峰值不超过1.5美元左右。 然而,在这个过程中查看任务管理器时,它会报告使用的内存大约为50美分,每秒爬升约1兆。 它会高达700megs + !! 中是否有一些已知的内存泄漏? 我可能在C#中做错了吗?导致这种情况的代码?

I am having a strange memory issue in my server application. This application accepts socket connections, passes messages around, then closes them. Using the .NET memory profiler from scitech, it reports reasonable memory behavior, hovering around 400k for live bytes, and peaking no higher than 1.5megs or so for total bytes used. However, looking in the task manager at the process, it reports the memory being used at around 50megs, climbing about 1 meg every second. It will get as high as 700megs+!! Are there some known memory leaks in ? Could I be doing something wrong in my C# code to cause this?

推荐答案

我做了类似的事情 - 没有内存泄漏。 只需几点指示: a)确保在完成处理后取消引用旧缓冲区 b)为了确保事情没有得到缓存,请尝试运行垃圾收集每次循环/解除分配后 - 检查来自 性能监视器的gargbage集合统计信息 - 看看是否真的发生了什么 c)当你看在任务管理器上确保你看过程内存 利用率而不是总内存消耗窗口有一个奇怪的方式来缓存东西。我发现刷新缓存(文件或其他)的一种方法是 写一个简单的程序,分配你的ram的90%,然后释放它(只需 确保你用C / C ++写的) 其他那个 - 发布代码;) " ja ******* @ gmail。 COM"写道: I have done simmilar thing - there were no memory leaks. Just a few pointers: a) make sure you dereference old buffers once you finished processing b) To make sure things arent getting cached try running garbage collection after each loop/deallocation - check the gargbage collection statistics from performance monitor - see if something is actually happenning c) When you look at task manager make sure you look at the process memory utilization and not total memory consumption windows has a wierd way of caching things. One way i found to flush the cache (file or otherwise) is to write a simple program that allocates 90% of your ram and then frees it (just make sure you write it in C / C++) Other then that - post the code ;) "ja*******@gmail" wrote: 我的服务器应用程序中存在一个奇怪的内存问题。这个应用程序接受套接字连接,传递消息,然后关闭它们。 使用scitech的.NET内存分析器,它报告合理的内存行为,徘徊在400k左右的实时字节,并且对于所使用的总字节数不超过1.5美分左右。 然而,在过程中查看任务管理器,它会报告它会高达700megs + !! 中是否存在已知的内存泄漏?我可以在我的C#代码中做错了吗? I am having a strange memory issue in my server application. This application accepts socket connections, passes messages around, then closes them. Using the .NET memory profiler from scitech, it reports reasonable memory behavior, hovering around 400k for live bytes, and peaking no higher than 1.5megs or so for total bytes used. However, looking in the task manager at the process, it reports the memory being used at around 50megs, climbing about 1 meg every second. It will get as high as 700megs+!! Are there some known memory leaks in ? Could I be doing something wrong in my C# code to cause this?

就像我说的,内存分析器显示垃圾收集 做它应该做的事情。记忆力不变。看看任务管理 专门在我的过程中显示事情不断增长。 我也从这个分析中获得了更多信息。似乎是本地内存增长发生在探查器调用的漏洞中 私有 - >托管堆 - > ;普通堆 - >生成#2 --->漏洞 根据漏洞的漏洞是: "孔"表示在两个分配的 实例之间未使用的内存。 "孔"当堆没有完全压缩时出现,因为固定垃圾收集器中的实例或优化需要。 任何人都知道它在说什么?什么是固定的 实例? Like I said, the memory profiler shows the garbage collection doing what it should. Memory there is constant. Looking in task manage specifically at my process though shows things constantly growing. I did get some more info from this profiling too. It seems to be that the native memory growth is occuring in what the profiler calls "holes" private-->managed heap-->normal heap-->generation #2--->"holes" according to the proflier holes are: "Holes" represent memory that is unused between two allocated instances. "Holes" appear when the heap is not fully compacted, due to pinned instances or optimizations in the garbage collector. anyone have any idea what it is talking about? what is a pinned instance?

" jack" < JA ******* @ gmail>在消息中写道 news:11 ********************** @ l41g2000cwc.googlegr oups ... "jack" <ja*******@gmail> wrote in message news:11**********************@l41g2000cwc.googlegr oups... 就像我说的那样,内存分析器显示了垃圾收集器正在做它应该做的事情。记忆力不变。特别是在我的过程中查看任务管理虽然显示事情不断增长。 我也从这个分析中获得了更多信息。似乎是本机内存增长发生在探查器调用的漏洞 私有 - >托管堆 - >普通堆 - >生成#2 --->漏洞 根据漏洞的漏洞是: 漏洞表示在两个分配的实例之间未使用的内存。 "孔"在堆未完全压缩时出现,由于固定实例或垃圾收集器中的优化。 任何人都知道它在说什么?什么是固定的实例? Like I said, the memory profiler shows the garbage collection doing what it should. Memory there is constant. Looking in task manage specifically at my process though shows things constantly growing. I did get some more info from this profiling too. It seems to be that the native memory growth is occuring in what the profiler calls "holes" private-->managed heap-->normal heap-->generation #2--->"holes" according to the proflier holes are: "Holes" represent memory that is unused between two allocated instances. "Holes" appear when the heap is not fully compacted, due to pinned instances or optimizations in the garbage collector. anyone have any idea what it is talking about? what is a pinned instance?

不确定配置文件是否区分Gen2和Large 对象堆(对于> 85Kb的对象,但是你能用Perfmon检查两个大小吗? 我问的原因是,与Gen0,1和2堆不同, LOH不会被压缩,结果是LOH会随着时间的推移而变得支离破碎,这取决于你的内存分配方案,如果你在 随机时尚这不是问题,但是如果你的分配对象会随着时间的推移而增长,那么它可能以如此大量的洞结束/> 不能用于存储不断增长的对象,没有内存可以进一步分配,并且进程因内存不足而死亡 例外。 所以你必须回答的问题是: - LOH是否在增长? - 你是否分配了大量的ob jects(通常是数组> 85 Kb)。 - 你是否随机分配方案。 Willy。

Not sure if the profiles makes a distinction between Gen2 and the Large Object heap (for objects > 85Kb), but could you check the sizes of both using Perfmon? The reason I ask is that, unlike the Gen0, 1 and 2 heaps, the LOH isn''t compacted, the result is that LOH gets fragmented over time depending on your memory allocation scheme, if you allocate random sized objects in a random fashion this isn''t an issue, but if your allocate objects that tend to grow in time, its possible to end with such a large number of holes that cannot be used to store the ever growing objects, that no memory can be allocated any further, and the process dies with a "Out of memory" exception. So the questions you have to answer are: - Is the LOH growing? - Are you allocating large objects (normally arrays > 85 Kb). - Is you allocation scheme random or not. Willy.

更多推荐

内存使用异常与异步服务器应用程序

本文发布于:2023-11-05 10:28:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1560586.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   异常   内存   服务器

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!