Comments (18)
Don't worry about it :)
I'm already doing that:
I've published the source here: https://github.com/LAB02-Admin/AudioDetectionTest
The relevant file is AudioManager.cs.
Maybe you could have a quick look when you have some spare time?
from coreaudio.
Wow @morphx666, this is some grade-A support :)
Been running for a while and no more memory leak, very happy with this, thank you!
I'll remove the manual disposes, test again later and let you know
from coreaudio.
It's all good, I was indeed just too focussed. GC just keeps the memory around to save resources, but it stays around 30-50MB. Its released when I run out of memory, but that normally doesn't happen.
Thanks for all your support @morphx666, really great :)
from coreaudio.
Hi @LAB02-Admin, if I understand correctly the error occurs when the default audio output device changes?
If that's the case, I will need to run some tests to see if I can reproduce the problem.
from coreaudio.
No that works fine. When the device changes, I dispose the AudioSessionManager2 (that's where it crashes) and fetch a new one. But I just realised that's probably not the right way.
What do you recommend? Just keep using the same MMDevice & AudioSessionManager2, even when the device changes, and only dispose when closing the application?
from coreaudio.
If I don't renew the AudioSessionManager2, it doesn't pick up sessions that are bound to the new device, so I can't keep using the same one. You probably already knew that though, just reporting what I tested :)
from coreaudio.
Each MMDevice has its own AudioSessionManager2 so when changing the device, the new device will contain its own set of sessions via its own AudioSessionManager2.
If you run this sample you will see that every time you select a different output device, the sessions change accordingly.
Regarding that sample, I will be soon updating it to support the creation and expiration of sessions.
from coreaudio.
Alright, thanks for the info! I'll be processing volume/session changes non stop, so what do you recommend regarding disposals? Memory leaks seem to be hard to avoid when working with audio devices.
from coreaudio.
The odd thing is, that when I'm just periodically looping through the devices and their sessions, the number of objects (and amount of unmanaged memory) just keep rising:
This is whether I dispose where objects can be disposed, or not.
These objects just keep rising in count:
Any idea what I'm doing wrong or what's happening?
from coreaudio.
I'm sorry for taking so long to reply.
Something that occurs to me would be to call RefreshSessions() on the AudioSessionManager2 every time you "re-connect" to an MMDevice. This will force a dispose on the object and will then re-create it with all sessions attached to that device.
from coreaudio.
Absolutely. Give me time until this weekend as I'm swamped!
from coreaudio.
Of course, good luck!
from coreaudio.
So now it happens that I cannot run the profiler on VS 2022 because of some weird bug.
I will check the code (manually) and I'll let you know if I can find anything...
from coreaudio.
Good news. I have just updated the library (1.12.0) to include a Dispose()
method for MMDevice
. This appears to solve the problem.
In your sample, I'd recommend doing the following changes:
- In the main loop of
MonitorAudioDevices
, add_audioDevice.Dispose();
at the end of thetry
block. - Remove the
device.AudioSessionManager2?.RefreshSessions();
from theGetSessions
function. - In that same function, add the following statements in the
finally
block:
session?.Dispose();
device.Dispose();
Please let me know if you notice any improvements.
If it works, it'd be interesting to test if removing all the manual Dispose's also works, as the GC should take care of that automatically.
from coreaudio.
After removing all disposes, the obj count keeps rising:
from coreaudio.
Another weird thing; the objects are going great, but the amount of unmanaged mem keeps rising (like 40MB with just a few MB for the app itself).
I noticed a drop in the unmanaged mem when the profiler called the GC, so I added this to run every 5 min:
GC.Collect();
GC.WaitForPendingFinalizers();
And now the memory stays 100% stable.
Weird though, never had to use that before.
from coreaudio.
hmmm... that doesn´t sound right. I guess I'll have to run some more tests and see if I can figure out what's going on.
from coreaudio.
Could be that I'm just too focussed on it now, and that GC will collect it eventually. I'll keep it running for a few days to see what happens.
from coreaudio.
Related Issues (18)
- PlaybackStopped Event fire multiple times
- Don't push a new NuGet package version for every commit HOT 2
- C# bibl
- [BUG] Exception on Enumerating NOTPRESENT devices HOT 1
- Mic peak volume HOT 1
- Detect device change/disconnect HOT 4
- [Samples] Error running the samples HOT 7
- Part to Connector and AudioVolumeLevel in Part.cs HOT 2
- Add license information and debug info to csproj HOT 13
- NuGet .NET Framework 4.6 support ? HOT 1
- AudioSessionManager2.OnSessionCreated never gets fired HOT 1
- Get AudioSessionControl2 object from OnSessionCreated event HOT 7
- Can't adjust the volume of certain applications HOT 2
- Protected memory exception when changing master volume HOT 2
- Bug: possible memory leak HOT 11
- DisplayName and IconPath are sometimes empty string. HOT 1
- NuGet Package? HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from coreaudio.