Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ You can optionally configure the `RecyclableStreamManager.ThrowExceptionOnToArra
| -----|-------|-------------|
| MemoryStreamCreated | Verbose | Logged every time a stream object is allocated. Fields: `guid`, `tag`, `requestedSize`, `actualSize`. |
| MemoryStreamDisposed | Verbose | Logged every time a stream object is disposed. Fields: `guid`, `tag`, `allocationStack`, `disposeStack`. |
| MemoryStreamDoubleDispose | Critical | Logged if a stream is disposed more than once. This indicates a logic error by the user of the stream. Dispose should happen exactly once per stream to avoid resource usage bugs. Fields: `guid`, `tag`, `allocationStack`, `disposeStack1`, `disposeStack2`. |
| MemoryStreamDoubleDispose | Verbose | Logged if a stream is disposed more than once. This indicates a logic error by the user of the stream. Dispose should happen exactly once per stream to avoid resource usage bugs. Fields: `guid`, `tag`, `allocationStack`, `disposeStack1`, `disposeStack2`. |
| MemoryStreamFinalized | Error | Logged if a stream has gone out of scope without being disposed. This indicates a resource leak. Fields: `guid`, `tag`, `allocationStack`.|
| MemoryStreamToArray | Verbose | Logged whenever `ToArray` is called. This indicates a potential problem, as calling `ToArray` goes against the concepts of good memory practice which `RecyclableMemoryStream` is trying to solve. Fields: `guid`, `tag`, `stack`, `size`.|
| MemoryStreamManagerInitialized| Informational | Logged when the `RecyclableMemoryStreamManager` is initialized. Fields: `blockSize`, `largeBufferMultiple`, `maximumBufferSize`.|
Expand Down
2 changes: 1 addition & 1 deletion src/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void MemoryStreamDisposed(Guid guid, string? tag, long lifetimeMs, string
/// <param name="disposeStack1">Call stack of the first dispose.</param>
/// <param name="disposeStack2">Call stack of the second dispose.</param>
/// <remarks>Note: Stacks will only be populated if RecyclableMemoryStreamManager.GenerateCallStacks is true.</remarks>
[Event(3, Level = EventLevel.Critical)]
[Event(3, Level = EventLevel.Verbose)]
public void MemoryStreamDoubleDispose(Guid guid, string? tag, string? allocationStack, string? disposeStack1,
string? disposeStack2)
{
Expand Down
2 changes: 1 addition & 1 deletion src/RecyclableMemoryStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ protected override void Dispose(bool disposing)
if (this.disposed)
{
string? doubleDisposeStack = null;
if (this.memoryManager.options.GenerateCallStacks)
if (this.memoryManager.GenerateDoubleDisposedStackTrace)
{
doubleDisposeStack = Environment.StackTrace;
}
Expand Down
8 changes: 8 additions & 0 deletions src/RecyclableMemoryStreamManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace Microsoft.IO
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics.Tracing;
using System.Runtime.CompilerServices;
using System.Threading;

Expand Down Expand Up @@ -82,6 +83,13 @@ public partial class RecyclableMemoryStreamManager

internal readonly Options options;

internal bool GenerateDoubleDisposedStackTrace =>
this.options.GenerateCallStacks &&
(
this.StreamDoubleDisposed != null ||
Events.Writer.IsEnabled(EventLevel.Verbose, EventKeywords.None)
);

/// <summary>
/// Settings for controlling the behavior of RecyclableMemoryStream
/// </summary>
Expand Down
Loading