简体   繁体   English

C#console logging:它会有内存问题吗?

[英]C# console logging: will it have memory issues?

So I'm working with a console app that will persist for days, weeks, or months at a time. 所以我正在使用一个控制台应用程序,它将持续数天,数周或数月。

It logs useful information to a text file, but it also writes to the Console. 它将有用信息记录到文本文件中,但它也会写入控制台。 Do I have to worry about the console memory not getting purged for some reason. 我是否必须担心控制台内存由于某种原因没有被清除。 It seems to be okay. 好像没问题。

I wrote a little test to run over lunch. 我写了一个小测试来吃午饭。 I added some randomly spaced letters so that my coworkers think I must be processing something large and can take a longer lunch. 我添加了一些随机间隔的字母,以便我的同事认为我必须处理大的东西并且可以吃更长的午餐。

for (Int64 i = 0; i < 1000000000000000000; i++)
            {
                string random = Path.GetRandomFileName();
                random = random.Replace(".", "");
                random = random.Replace("m", "               ");
                random = random.Replace("a", "                                  ");
                random = random.Replace("h", "                         ");


                Console.WriteLine("i " + i + "   " + random);

            }

So, memory looks stable without writing to a file. 因此,内存看起来稳定而无需写入文件。 I just want some confirmation that if I do have a memory issue, it's not from the console... 我只是想要一些确认,如果我确实有内存问题,那么它不是来自控制台......

Memory does climb ever so slightly if I log it to a text file as well. 如果我将其记录到文本文件中,内存确实会略微攀升。

It logs useful information to a text file, but it also writes to the Console. 它将有用信息记录到文本文件中,但它也会写入控制台。 Do I have to worry about the console memory not getting purged for some reason. 我是否必须担心控制台内存由于某种原因没有被清除。 It seems to be okay. 好像没问题。

Not unless you have your console set up to have an enormous buffer, or it's redirected to an in-memory file system, or something like that. 除非您将控制台设置为具有巨大的缓冲区,或者将其重定向到内存中的文件系统,或者类似的东西。 In normal situations, it should be fine. 在正常情况下,应该没问题。

Not an issue, any text that scrolls off the console buffer as specified by Console.SetBufferSize() falls in the bit-bucket. 不是问题,任何由Console.SetBufferSize()指定的滚动控制台缓冲区的文本都属于位桶。 The maximum buffer size is 64KB, a restriction that the Console class forgets to check btw. 最大缓冲区大小为64KB,这是Console类忘记检查btw的限制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM