如何避免实时.NET应用程序的垃圾收集? [英] How to avoid garbage collection in real time .NET application?

查看:86
本文介绍了如何避免实时.NET应用程序的垃圾收集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

林书面方式从该网络接收的消息的金融C#应用程序,根据消息类型并将其转化为不同的对象,并finaly应用应用程序的业务逻辑上它们。

I'm writting a financial C# application which receive messages from the network, translate them into different object according to the message type and finaly apply the application business logic on them.

的一点是,业务逻辑应用后,我很肯定我永远不会再需要这个实例。而不是等待垃圾回收器来释放他们,我想明确地删除它们。

The point is that after the business logic is applied, I'm very sure I will never need this instance again. Rather than to wait for the garbage collector to free them, I'd like to explicitly "delete" them.

有没有更好的方法,这样做在C#中,我应该使用对象池总是重复使用同一组的实例,或者是有一个更好的策略。

Is there a better way to do so in C#, should I use a pool of object to reuse always the same set of instance or is there a better strategy.

,目的是为了避免垃圾收集过程中一个关键的时间过程中使用的任何CPU。

The goal being to avoid the garbage collection to use any CPU during a time critical process.

推荐答案

不要删除它们的时候了。调用垃圾收集器为每个对象是一个坏主意。通常情况下,你的真正的不想惹垃圾收集器在所有的,甚至是时间关键过程都只是比赛情况随时会发生,如果他们是敏感的。

Don't delete them right away. Calling the garbage collector for each object is a bad idea. Normally you really don't want to mess with the garbage collector at all, and even time critical processes are just race conditions waiting to happen if they're that sensitive.

但如果你知道你有VS忙你的应用程序轻负载期间,你可以尝试一个更一般的GC.Collect的(),当你达到光照时间,以鼓励下忙期之前的清理工作。

But if you know you'll have busy vs light load periods for your app, you might try a more general GC.Collect() when you reach a light period to encourage cleanup before the next busy period.

这篇关于如何避免实时.NET应用程序的垃圾收集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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