-
Notifications
You must be signed in to change notification settings - Fork 831
Closed
Labels
Description
Description
When working on #1962 i did notice what in ReusableStringWriter underlying buffer of StringBuilder can grow as much as biggest message we log, so in case we log some really big message, like more than 32_000 symbols(or even >1_000_000) we are gonna stuck with StringBuilder buffer this size forever even if we never log anything this big for application lifetime.
Expected behavior
If "StringBuilder.Capacity > 32748" or any other reasonable buffer size threshold we dispose ReusableStringWriter, something like this:
/// <summary>
/// Clear this instance and prepare it for reuse in the future.
/// </summary>
protected override void Dispose(bool disposing)
{
// We don't call base.Dispose because all it does is mark the writer as closed so it can't be
// written to and we want to keep it open as reusable writer.
var sb = GetStringBuilder();
if (sb.Capacity > 32748)
{
base.Dispose();
return;
}
sb.Clear();
_pooledWriter = this;
}