Comments (2)
I hope I can express everything correctly, feel free to question me.
It seems that C++ SoLoud has no direct
dispose()
equivalent. The closest I could find is the destructor (AudioSource::~AudioSource()
) insoloud_audiosource.cpp:208
, which just callsstop()
, which in turn callsSoloud::stopAudioSource()
, which callsstopVoice_internal()
. I'm not sure if we're calling this from Dart via FFI at all.
Exact. Those methods are called with SoLoud.disposeSound()
or SoLoud.disposeAllSound()
which internally calls AudioSource::~AudioSource()
.
The SoLoud.stop()
just stops the handle, but doesn't dispose the SoLoud.AudioSource
.
A remark: the AudioSource
in Soloud lib, can be any kind of audio: a LoadMode.memory
, a LoadMode.disk
or even a text to speech sound. It can be subclassed to have more modes like maybe a streaming from an internet radio or a remote audio file.
My question is: when my game plays 10 songs in a row, do all these songs just stay in (C++) memory forever? I'm assuming their data is not in memory (because
LoadMode.disk
) but still.
I did some tests:
- load into mem 14 songs
- I see increasing system memory of about 2 GB
- I used
SoLoud.instance.disposeSound
for each songs (also tried withSoLoud.instance.disposeAllSound()
) - I see decreasing system memory of about 2 GB
using the functions mentioned above, the sound(s) is cleared disposing also the SoLoud::AudioSource
which also free the memory.
From what I can understand, our
disposeSound()
only removes the AudioSource fromactiveSounds
(on the Dart side) and fromsounds
(on thePlayer
/player.cpp
) side. NoSoLoud
API is called. (Or is the destructor called because the ActiveSound is erased from thesounds
vector?)
For the above considerations, yes, the destructor is called when removing the sound from vector.
If you see the memory not freed, can you please paste some code to try? I tried the following:
await SoLoud.instance.initialize();
final audioSources = <AudioSource>[];
audioSources.add(await SoLoud.instance.loadFile('complete/audio/file/path.mp3'));
// add here as many audio file you want (whoops, no! Less the 16 :) )
for (final s in audioSources) {
await SoLoud.instance.play(s);
}
await delay(5000); // breakpoint here to see memory increasing
// for (final s in audioSources) {
// await SoLoud.instance.disposeSound(s);
// }
await SoLoud.instance.disposeAllSound();
SoLoud.instance.deinit(); // breakpoint here to see memory decreasing
from flutter_soloud.
Thank you so much! This is exactly what I wanted to know. I really appreciate you confirmed it experimentally, too.
I'll keep this open until I incorporate this information into Dart doc comments (but it's already useful for the codelab I'm working on).
from flutter_soloud.
Related Issues (20)
- feat: Add custom source data for capturing HOT 3
- fix: Crash when opening a malformed mp3 file HOT 2
- feat: Make it possible to "instance" SoLoud? HOT 3
- feat: Find a better mechanism than the `audioEvent` stream for listening to changes in the engine HOT 3
- feat: Fail-fast more often HOT 2
- feat: WASM support HOT 27
- chore: Address C++ compilation warnings HOT 2
- proposal: Another set of renames HOT 4
- feat: Implement setProtectVoice() HOT 1
- fix: Wrong error reported when trying to add a filter twice
- bug: crash on deinit() HOT 1
- fix: App asks for microphone permission even though it's not using it HOT 4
- feat: Simplified Recording Mechanism HOT 12
- feat: WaveForm for complete Audiofile HOT 1
- perf: Ability to play precise sound sequences HOT 3
- fix: Missing audio on playing a loaded url HOT 1
- fix: Init error on hot restart HOT 3
- fix: handles become invalid at unknown points HOT 9
- MA_NODE_FLAG_SILENT_OUTPUT duplicates API recursive triggers (bangs) HOT 2
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 flutter_soloud.