Convert span refs to weak refs to avoid memory leaks
Changeset
Convert the context stack in SpanFactory.cs to Stack<WeakReference<ISpanContext>>
Convert _preStartSpans and _finishedSpanQueue in Tracer.cs to Stack<WeakReference<ISpanContext>>
Fix bug in Tracer.cs where OnEndCallbacks ran twice on pre start spans
Convert pending network spans collection to Dictionary<WeakReference<BugsnagUnityWebRequest>, Span>
Converted multiple E2E tests that used time based batches to use batchsize instead to avoid race conditions
Some code formatting refactor
Changes to Span.Discard(), Span.End() and cleaning span collections in BugsnagPerformance.
Now that the collection BugsnagPerformance._potentiallyOpenSpans is a weak reference collection, it's no longer important to remove spans from it when they are ended. Because of this it is also no longer necessary to call the onSpanEnd delegate when a span is discarded.
The discard method is now much simpler and more performant, as is the normal endSpan method.
_potentiallyOpenSpans and _networkSpans are now cleaned up whenever the app is backgrounded.
Testing
Making sure nothing is broken by this change is covered by existing E2E tests.
Garbage collection of forgotten about spans was tested manually.
Goal
Convert span refs to weak refs to avoid memory leaks
Changeset
SpanFactory.cs
toStack<WeakReference<ISpanContext>>
_preStartSpans
and_finishedSpanQueue
inTracer.cs
toStack<WeakReference<ISpanContext>>
Tracer.cs
whereOnEndCallbacks
ran twice on pre start spansDictionary<WeakReference<BugsnagUnityWebRequest>, Span>
Changes to Span.Discard(), Span.End() and cleaning span collections in BugsnagPerformance.
Now that the collection BugsnagPerformance._potentiallyOpenSpans is a weak reference collection, it's no longer important to remove spans from it when they are ended. Because of this it is also no longer necessary to call the onSpanEnd delegate when a span is discarded.
The discard method is now much simpler and more performant, as is the normal endSpan method.
_potentiallyOpenSpans and _networkSpans are now cleaned up whenever the app is backgrounded.
Testing
Making sure nothing is broken by this change is covered by existing E2E tests. Garbage collection of forgotten about spans was tested manually.