Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Force QML to release memory used by Audio (Android error -19)



  • I have an android app with approx 50 sound files. After playing approx 10 of these files it appears that Android runs out of memory, and I see this in the debug output:

    E libOpenSLES: Too many objects
    W libOpenSLES: Leaving Engine::CreateAudioPlay (SL_RESULTS_MEMORY_FAILURE)
    ...
    E MediaPLayerNative: error (1,-19)
    E MediaPlayer: error (1,-19)
    

    and this sound file will not play.

    From what I found online -19 means out of memory error. So right after each audio file plays I set source to "" based on suggestions on stackoverflow, but it did help (or at least not enough). I also reduced audio to low bitrate and single channel. But it's still not enough.

    I tried switching from Audio to Multimedia but it made no difference. I even went so far as to use a Loader to load the audio component, and unload it after the file played, and call gc() for garbage collection. Surprisingly, that made no difference either. For some reason QML is not freeing the memory used by audio files after they are played (and they are inside a QRC in this case).

    Help?! This seems like a pretty major issue - is there a workaround / fix? (using Qt 5.15.2)



  • @ocgltd
    Well I solved it - for anyone else experiencing this here is the solution. It (appears) that QML will not release audio players, so every one you create is held forever.

    The solution is to create a single audio player, in a singleton, and then use that to play (non-overlapping) audio files; changing the source each time.



  • @ocgltd
    Well I solved it - for anyone else experiencing this here is the solution. It (appears) that QML will not release audio players, so every one you create is held forever.

    The solution is to create a single audio player, in a singleton, and then use that to play (non-overlapping) audio files; changing the source each time.


Log in to reply