AudioSwitcher icon indicating copy to clipboard operation
AudioSwitcher copied to clipboard

OutOfMemoryException

Open AdamoT opened this issue 5 years ago • 5 comments

The issue is raised every time I leave my application running for about 3 days. I don't have a full stacktrace, because the exception is caught in AppDomain.CurrentDomain.UnhandledException but it's something like this:

2019-03-19 12:22:50.6656|ERROR|WindowsServiceClient.WindowsClient|Domain unhandled exceptionSystem.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
   at System.Diagnostics.NtProcessInfoHelper.GetProcessInfos(IntPtr dataPtr, Predicate`1 processIdFilter)
   at System.Diagnostics.NtProcessInfoHelper.GetProcessInfos(Predicate`1 processIdFilter)
   at System.Diagnostics.ProcessManager.GetProcessInfosCore(String machineName, Boolean isRemoteMachine)
   at System.Diagnostics.Process.GetProcesses(String machineName)
   at System.Diagnostics.Process.GetProcesses()
   at AudioSwitcher.AudioApi.CoreAudio.ProcessMonitor.ProcessTerminatedCheck(Object state)
   at System.Threading.TimerQueueTimer.CallCallbackInContext(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.TimerQueueTimer.CallCallback()
   at System.Threading.TimerQueueTimer.Fire()
   at System.Threading.TimerQueue.FireNextTimers()
   at System.Threading.TimerQueue.AppDomainTimerCallback()
2019-03-19 12:22:26.2306|ERROR|WindowsServiceClient.WindowsClient|Domain unhandled exceptionSystem.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
   at System.Collections.ArrayList.set_Capacity(Int32 value)
   at System.Collections.ArrayList.EnsureCapacity(Int32 min)
   at System.Collections.ArrayList.Add(Object value)
   at System.Diagnostics.NtProcessInfoHelper.GetProcessInfos(IntPtr dataPtr, Predicate`1 processIdFilter)
   at System.Diagnostics.NtProcessInfoHelper.GetProcessInfos(Predicate`1 processIdFilter)
   at System.Diagnostics.ProcessManager.GetProcessInfosCore(String machineName, Boolean isRemoteMachine)
   at System.Diagnostics.Process.GetProcesses(String machineName)
   at System.Diagnostics.Process.GetProcesses()
   at AudioSwitcher.AudioApi.CoreAudio.ProcessMonitor.ProcessTerminatedCheck(Object state)
   at System.Threading.TimerQueueTimer.CallCallbackInContext(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.TimerQueueTimer.CallCallback()
   at System.Threading.TimerQueueTimer.Fire()
   at System.Threading.TimerQueue.FireNextTimers()
   at System.Threading.TimerQueue.AppDomainTimerCallback()
2019-03-19 12:22:50.6656|ERROR|WindowsServiceClient.WindowsClient|Domain unhandled exceptionSystem.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
   at System.String.CtorCharPtrStartLength(Char* ptr, Int32 startIndex, Int32 length)
   at System.Runtime.InteropServices.Marshal.PtrToStringUni(IntPtr ptr, Int32 len)
   at System.Diagnostics.NtProcessInfoHelper.GetProcessInfos(IntPtr dataPtr, Predicate`1 processIdFilter)
   at System.Diagnostics.NtProcessInfoHelper.GetProcessInfos(Predicate`1 processIdFilter)
   at System.Diagnostics.ProcessManager.GetProcessInfosCore(String machineName, Boolean isRemoteMachine)
   at System.Diagnostics.Process.GetProcesses(String machineName)
   at System.Diagnostics.Process.GetProcesses()
   at AudioSwitcher.AudioApi.CoreAudio.ProcessMonitor.ProcessTerminatedCheck(Object state)
   at System.Threading.TimerQueueTimer.CallCallbackInContext(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.TimerQueueTimer.CallCallback()
   at System.Threading.TimerQueueTimer.Fire()
   at System.Threading.TimerQueue.FireNextTimers()
   at System.Threading.TimerQueue.AppDomainTimerCallback()
2019-03-19 12:22:50.6656|ERROR|WindowsServiceClient.WindowsClient|Domain unhandled exceptionSystem.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
   at System.Linq.Set`1.Resize()
   at System.Linq.Set`1.Find(TElement value, Boolean add)
   at System.Linq.Enumerable.<ExceptIterator>d__73`1.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at AudioSwitcher.AudioApi.CoreAudio.ProcessMonitor.ProcessTerminatedCheck(Object state)
   at System.Threading.TimerQueueTimer.CallCallbackInContext(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.TimerQueueTimer.CallCallback()
   at System.Threading.TimerQueueTimer.Fire()
   at System.Threading.TimerQueue.FireNextTimers()
   at System.Threading.TimerQueue.AppDomainTimerCallback()

The system I'm running has 32GB of RAM and at the point when this exception is invoked I don't observe any huge system memory consumption.

AdamoT avatar Mar 19 '19 11:03 AdamoT

Hi, I have the same problem. Memory leak diagnosed with a profiler.

Azmarel avatar Apr 23 '19 06:04 Azmarel

Have you guys moved to other lib or fixed it somehow?

alexandre-leites avatar Sep 11 '20 14:09 alexandre-leites

Not really. The most important functionallity for me was to be able to get/change default system audio device, which is an undocumented windows feature and I haven't found any other lib that even attempts to implement it. If someone knows about one, please let me know. For now, I just restart my service when this issue happens

AdamoT avatar Sep 14 '20 10:09 AdamoT

The API as used by the 1.x GUI doesn't seem to have this problem, or doesn't trigger it, so perhaps it's a matter of using a specific working version?

Luckz avatar Sep 15 '20 02:09 Luckz

I have the same problem, it was only running a few hours

System.OutOfMemoryException HResult=0x8007000E Message=Array dimensions exceeded supported range. Source=mscorlib StackTrace: at System.Collections.Generic.Dictionary2.Resize(Int32 newSize, Boolean forceNewHashCodes) at System.Collections.Generic.Dictionary2.Insert(TKey key, TValue value, Boolean add) at System.Threading.Tasks.Task.AddToActiveTasks(Task task) at System.Threading.Tasks.Task.ScheduleAndStart(Boolean needsProtection) at System.Threading.Tasks.Task.InternalStartNew(Task creatingTask, Delegate action, Object state, CancellationToken cancellationToken, TaskScheduler scheduler, TaskCreationOptions options, InternalTaskOptions internalOptions, StackCrawlMark& stackMark) at System.Threading.Tasks.TaskFactory.StartNew(Action action) at AudioSwitcher.AudioApi.Observables.AsyncBroadcaster1.RaiseAllObserversAsync(Action1 observerAction) at AudioSwitcher.AudioApi.CoreAudio.ProcessMonitor.ProcessTerminatedCheck(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.TimerQueueTimer.CallCallback() at System.Threading.TimerQueueTimer.Fire() at System.Threading.TimerQueue.FireNextTimers()

hvanzyll avatar Oct 14 '21 04:10 hvanzyll