-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Closed
Milestone
Description
Description
I found an edge case in the PriorityQueue<TElement, TPriority> collection, where enqueuing an element
might fail, but nonetheless the Count increases.
Reproduction Steps
using System;
using System.Collections.Generic;
class Program
{
static void Main()
{
PriorityQueue<int, int> queue = new(new (int, int)[300_000_000]);
Console.WriteLine($"Before Enqueue, Count: {queue.Count:#,0}");
try
{
queue.Enqueue(1, 1);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.WriteLine($"After Enqueue, Count: {queue.Count:#,0}");
}
}In my PC I get this output, after around 30 seconds of execution time:
Before Enqueue, Count: 300,000,000
Exception of type 'System.OutOfMemoryException' was thrown.
After Enqueue, Count: 300,000,001
Expected behavior
After failing to Enqueue, the Count should preserve its previous value (300,000,000).
Actual behavior
The Count increases to 300,000,001.
Regression?
No response
Known Workarounds
No response
Configuration
- .NET 6.0
- Console application
- 64-bit operating system, x64-based processor
Other information
No response
Reactions are currently unavailable