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 leaks? #776

Open
liuchuancong opened this issue Apr 17, 2024 · 10 comments
Open

memory leaks? #776

liuchuancong opened this issue Apr 17, 2024 · 10 comments

Comments

@liuchuancong
Copy link

After playing the video for an hour in Windows, the content soared from 300MB to 1G. The non-caching attribute has been set. Is this a memory leak in the player?

Here is my simple code :

player = Player();
      if (player.platform is NativePlayer) {
        await (player.platform as dynamic).setProperty('cache', 'no');
      }
      mediaPlayerController = media_kit_video.VideoController(player);
      setDataSource(datasource);
      mediaPlayerController.player.stream.playing.listen((bool playing) {
        if (playing) {
          isPlaying.value = true;
        } else {
          isPlaying.value = false;
        }
      });
      mediaPlayerController.player.stream.error.listen((event) {
        if (event.toString().contains('Failed to open')) {
          hasError.value = true;
          isPlaying.value = false;
        }
      });
      mediaPlayerControllerInitialized.value = true;
@justbendev
Copy link

I I'm running 16 RTSP Streams and ram usage go up pretty quick to around 2900 MB in only 15 minutes.
Note : 16 Player instances alone without any media is already 700-800MB of memory

The cache should be default be limited to 32MB but i don't think this is actually being applied.
After seeing you use setProperty i investigated the function and read all available mpv options and applied theses options.

Player ply = Player();
      (ply.platform as dynamic).setProperty('cache', 'no');                   // --cache=<yes|no|auto>
      (ply.platform as dynamic).setProperty('cache-secs', '0');               // --cache-secs=<seconds> with cache but why not.
      (ply.platform as dynamic).setProperty('demuxer-seekable-cache', 'no');  // --demuxer-seekable-cache=<yes|no|auto> Redundant with cache but why not.
      (ply.platform as dynamic).setProperty('demuxer-max-back-bytes', '0');   // --demuxer-max-back-bytes=<bytesize>
      (ply.platform as dynamic).setProperty('demuxer-donate-buffer', 'no');   // --demuxer-donate-buffer==<yes|no>

Now it's stable and won't go over 1,688 MB after hours of running it

All my memory usage numbers are in Debug mode

@liuchuancong
Copy link
Author

@justbendev Thanks for the recovery, I'll try to see if the problem recurs, you're my hero!

@liuchuancong
Copy link
Author

This problem still exists,increase 30M every 10 minutes when playing m3u8 media files

@sherlockvn
Copy link

I run the profile, its actually leaks, I just open and close video again 8 times, and see some component inVideoTexture class is not disposed.
image

@bdlukaa
Copy link

bdlukaa commented May 15, 2024

It looks like these two properties are not being disposed at the dispose() method.

late final _contextNotifier = ValueNotifier<BuildContext?>(null);
late final ValueNotifier<VideoViewParameters> _videoViewParametersNotifier =
media_kit_video_controls.VideoStateInheritedWidget.maybeOf(
context,
)?.videoViewParametersNotifier ??
ValueNotifier<VideoViewParameters>(
VideoViewParameters(
width: widget.width,
height: widget.height,
fit: widget.fit,
fill: widget.fill,
alignment: widget.alignment,
aspectRatio: widget.aspectRatio,
filterQuality: widget.filterQuality,
controls: widget.controls,
subtitleViewConfiguration: widget.subtitleViewConfiguration,
),
);

@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
_wakelock.disable();
for (final subscription in _subscriptions) {
subscription.cancel();
}
super.dispose();
}

@abdelaziz-mahdy
Copy link
Member

It looks like these two properties are not being disposed at the dispose() method.

late final _contextNotifier = ValueNotifier<BuildContext?>(null);
late final ValueNotifier<VideoViewParameters> _videoViewParametersNotifier =
media_kit_video_controls.VideoStateInheritedWidget.maybeOf(
context,
)?.videoViewParametersNotifier ??
ValueNotifier<VideoViewParameters>(
VideoViewParameters(
width: widget.width,
height: widget.height,
fit: widget.fit,
fill: widget.fill,
alignment: widget.alignment,
aspectRatio: widget.aspectRatio,
filterQuality: widget.filterQuality,
controls: widget.controls,
subtitleViewConfiguration: widget.subtitleViewConfiguration,
),
);

@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
_wakelock.disable();
for (final subscription in _subscriptions) {
subscription.cancel();
}
super.dispose();
}

leaks for the widgets have been fixed in this pr #823 checking with devtools now shows that all the widgets gets disposed correctly

@ToneyWang
Copy link

I used MediaKIt to play RTSP video streams and the memory increased to 1GiB within 3 hours. How do I set the parameters? thanks.
@abdelaziz-mahdy

@abdelaziz-mahdy
Copy link
Member

I used MediaKIt to play RTSP video streams and the memory increased to 1GiB within 3 hours. How do I set the parameters? thanks. @abdelaziz-mahdy

sadly i think its an ffmpeg bug since it happens in mpv and fvp

@ToneyWang
Copy link

I used MediaKIt to play RTSP video streams and the memory increased to 1GiB within 3 hours. How do I set the parameters? thanks. @abdelaziz-mahdy

sadly i think its an ffmpeg bug since it happens in mpv and fvp

When using TCP in FVP, this bug will not occur.

@abdelaziz-mahdy
Copy link
Member

I used MediaKIt to play RTSP video streams and the memory increased to 1GiB within 3 hours. How do I set the parameters? thanks. @abdelaziz-mahdy

sadly i think its an ffmpeg bug since it happens in mpv and fvp

When using TCP in FVP, this bug will not occur.

nice, glad to hear that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants