Code Monkey home page Code Monkey logo

Comments (2)

alnitak avatar alnitak commented on May 25, 2024

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()) in soloud_audiosource.cpp:208, which just calls stop(), which in turn calls Soloud::stopAudioSource(), which calls stopVoice_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 with SoLoud.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 from activeSounds (on the Dart side) and from sounds (on the Player / player.cpp) side. No SoLoud API is called. (Or is the destructor called because the ActiveSound is erased from the sounds 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.

filiph avatar filiph commented on May 25, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.