Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak after player.dispose() #1381

Open
Colton127 opened this issue Dec 24, 2024 · 0 comments
Open

Memory leak after player.dispose() #1381

Colton127 opened this issue Dec 24, 2024 · 0 comments
Assignees
Labels
1 backlog bug Something isn't working

Comments

@Colton127
Copy link

Colton127 commented Dec 24, 2024

Which API doesn't behave as documented, and how does it misbehave?
Some resources are retained despite calling player.dispose().

Minimal reproduction project
https://github.com/Colton127/just_audio/blob/fix_memleak/just_audio/example/lib/main.dart

To Reproduce
Steps to reproduce the behavior:

  1. Run example project above
  2. Tap loop IconButton
  3. Check memory profiler, you can see that each instance of AudioPlayer is retained despite dispose being called

Expected behavior
AudioPlayer and its dependencies should be completely freed following dispose()

Screenshots
Output of linked minimal reproduction project, which creates 100 AudioPlayer instances and sets an AudioSource before disposing the player:

Screenshot 2024-12-23 at 8 49 05 PM

Smartphone (please complete the following information):

  • Device: iPad 8th generation

  • OS: iOS 18.2

  • Device: iPhone 16 Pro Max Simulator

  • OS: iOS 18.2 (Simulator)

Flutter SDK version

[✓] Flutter (Channel stable, 3.27.1, on macOS 15.1.1 24B91 darwin-x64, locale
    en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 16.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.2)
[✓] VS Code (version 1.96.2)

Additional context

  • In my testing, the issue does not occur on Android.
  • Calling await player.stop() before dispose appears to resolve the problem

Adding the following code to dispose() appears to fix the issue:

  Future<void> dispose() async {
    if (_disposed) return;
    _disposed = true;
    _playbackEventSubscription?.cancel();
    _playerDataSubscription?.cancel();
.....

Though I'm unsure if this is a proper fix or just a workaround.

@Colton127 Colton127 added 1 backlog bug Something isn't working labels Dec 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1 backlog bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants