Following program causes garbage collection
See original GitHub issue
using ZeroLog;
using ZeroLog.Appenders;
using ZeroLog.Configuration;
LogManager.Initialize(new ZeroLogConfiguration()
{
LogMessagePoolSize = 10240,
RootLogger =
{
Appenders =
{
new ConsoleAppender()
}
}
});
var logger = LogManager.GetLogger("Main");
var rand = new Random();
while (true)
{
var r = rand.Next();
Thread.Sleep(100);
logger.Info($"rand: {r}");
}
when running the above program using 2.0.1 nuget package of ZeroLog, I can see the system is doing garbage collection.
Maybe I’m misunderstanding what is going on, but I thought that the logging was meant to be zero allocation and thus no garbage should be created.
Issue Analytics
- State:
- Created 8 months ago
- Reactions:2
- Comments:5 (3 by maintainers)
Top Results From Across the Web
What is garbage collection? Automated memory ...
The biggest issues are the overhead of the garbage collector; unpredictable stalls when the garbage collector decides to run; and increased lag ...
Read more >What is garbage collection (GC) in programming?
Garbage collection is an ongoing process that requires central processing unit resources, which can affect an application's general performance or even disrupt ...
Read more >Garbage Collection in Java
Whenever JVM runs the Garbage Collector program, then only the object will be destroyed. But when JVM runs Garbage Collector, we can not...
Read more >Garbage Collection and Performance
Read about issues related to garbage collection and memory usage. Learn to minimize the effect of garbage collection on your applications.
Read more >Garbage Collection in Java – What is GC and How it Works ...
Garbage collection makes Java memory efficient because it removes the unreferenced objects from heap memory and makes free space for new objects ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Well, oops. Sorry about that. 😬
Turns out,
UTF8Encoding
has an optimization thatOSEncoding
does not: the baseEncoding
class allocates by default, andUTF8Encoding
overrides that part. 😞 Maybe that’s something I should report as an issue withOSEncoding
…Just FYI, you have some easier solutions that avoid allocations than copying the
ConsoleAppender
code:An appender that inherits
ConsoleAppender
Using
new TextWriterAppender(Console.Out)
with ZeroLog v2.1.0-pre2 (but that removes color)Setting
Console.OutputEncoding = Encoding.UTF8;
before theConsoleAppender
is instantiated should also do the trick (if you can do that for your app).In any case, that will be fixed in ZeroLog v2.1.0 final. 🙂
Thanks for the prompt response and can confirm that in my real app I’m no longer seeing allocations.