xenolightning / AudioSwitcher

.NET Library which facilitates interacting with Audio Devices on Windows
Microsoft Public License
248 stars 53 forks source link

OutOfMemoryException #44

Open AdamoT opened 5 years ago

AdamoT commented 5 years ago

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.

Azmarel commented 5 years ago

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

alexandre-leites commented 4 years ago

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

AdamoT commented 4 years ago

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

Luckz commented 4 years ago

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?

hvanzyll commented 3 years ago

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()