Opened 6 months ago

Closed 6 months ago

#18654 closed bug (fixed)

Memory leak - MediaPlayer

Reported by: kim1963 Owned by: pulkomandy
Priority: normal Milestone: R1/beta5
Component: Audio & Video/Codecs Version: R1/beta4
Keywords: regression Cc:
Blocked By: Blocking:
Platform: All

Description (last modified by kim1963)

Memory leakage when playing audio files with a MediaPlayer. Playing a big singular file. All audio formats create a leakage of memory. Reproduction of video files does not lead to a memory leak . Checked for 64 bits 57367 night build.

Change History (27)

comment:1 by kim1963, 6 months ago

Description: modified (diff)

comment:2 by Starcrasher, 6 months ago

Originally reported here https://discuss.haiku-os.org/t/memory-leak-mediaplayer/ Note that when kim1963 says a big file, it's about an eleven hours of audio.

comment:3 by waddlesplash, 6 months ago

Component: Audio & VideoAudio & Video/Codecs
Owner: changed from nobody to pulkomandy

comment:4 by waddlesplash, 6 months ago

Looks like this may be a kernel leak and not a userland one.

Is this reproducible in any VMs or only on bare metal?

in reply to:  4 comment:5 by kim1963, 6 months ago

Replying to waddlesplash:

Looks like this may be a kernel leak and not a userland one.

Is this reproducible in any VMs or only on bare metal?

Perhaps the code check with a static analyzer can clarify something?

https://habr.com/ru/companies/pvs-studio/articles/461253/

https://pvs-studio.com/en/

Last edited 6 months ago by kim1963 (previous) (diff)

comment:6 by kim1963, 6 months ago

I checked large audio files in other player / QMplay2 and QMMP /. There are no problems with the memory leak.

comment:7 by victroniko, 6 months ago

Can confirm this looks like something kernel/MediaKit related: i'm seeing the same behavior in StreamRadio. If left running and playing a stream, RAM usage climbs steadily without stop. Bug is easily reproducible this way.

I'm listening some music now, it's been ~20min and RAM usage is nearing 850MB. (edit. hrev57353, baremetal)

Last edited 6 months ago by victroniko (previous) (diff)

in reply to:  4 comment:8 by kim1963, 6 months ago

Replying to waddlesplash:

Looks like this may be a kernel leak and not a userland one.

Is this reproducible in any VMs or only on bare metal?

On bare metal.

Unfortunately, I have no way to check it in a virtual machine.

comment:9 by waddlesplash, 6 months ago

Does RAM usage go back down once MediaPlayer/StreamRadio is closed?

in reply to:  9 comment:10 by kim1963, 6 months ago

Replying to waddlesplash:

Does RAM usage go back down once MediaPlayer/StreamRadio is closed?

Yes

comment:11 by tzu_mi, 6 months ago

Hrev 57365, x64, bare metal Memory usage keeps growing playing tracks in loop or playing playlists

comment:12 by pulkomandy, 6 months ago

For StreamRadio the rssue is possibly different: the entire stream is kept in memory forever due to the way the media kit implements http streams.

Also, I don't seewhy this would point to a kernel problem in either case, more likely it is a media kit (or network kit in the case of streamradio) problem.

In any case pl ase report the streamradio problem to StreamRadio bugtracker first, it is not a good idea to investigate two possibly related but different issues in the same bugreport (we can't split a bugreport in trac, but we can always close one bugreport as aduplicate of another if they end up being the same)

in reply to:  12 comment:13 by madmax, 6 months ago

Replying to pulkomandy:

For StreamRadio the rssue is possibly different: the entire stream is kept in memory forever due to the way the media kit implements http streams.

I can confirm that. I saw it and even started rewriting it back when StreamRadio got a bit of attention due to the removal of some deprecated API, but other issues got in the way. There's already a report in its bugtracker.

in reply to:  12 comment:14 by victroniko, 6 months ago

Replying to pulkomandy:

In any case pl ase report the streamradio problem to StreamRadio bugtracker first, it is not a good idea to investigate two possibly related but different issues in the same bugreport (we can't split a bugreport in trac, but we can always close one bugreport as aduplicate of another if they end up being the same)

I spun up two VMs, one with Beta4 and another with hrev57367. Installed StreamRadio and started the same stream on both VMs. After 1hr of streaming, RAM usage sits at ~350Mb on Beta4, and nearing 2Gb on said nightly. So I still think there's something wrong @ OS-level, and maybe both leaks add up?

In any case I won't test w/StreamRadio anymore (until needed/asked for), to isolate that issue.

in reply to:  4 comment:15 by kim1963, 6 months ago

Replying to waddlesplash:

Looks like this may be a kernel leak and not a userland one.

Is this reproducible in any VMs or only on bare metal?

I checked the memory leak on the release of 64 bits 56578+93 - there is no memory leakage!

comment:16 by pulkomandy, 6 months ago

Keywords: regression added
Milestone: UnscheduledR1/beta5

Moving to r1beta5 since it's a regression

comment:17 by jackburton, 6 months ago

in reply to:  17 comment:18 by korli, 6 months ago

Replying to jackburton:

Any chance this commit could be the culprit? https://github.com/haiku/haiku/commit/9858be4f63c2148aa18bd65e139586e3e837f8c2

Please someone test with a hrev before hrev57350.

comment:19 by victroniko, 6 months ago

Testing MediaPlayer side-to-side on fresh Haiku VMs, with a sample ~35min 85Mb MP3 file:

hrev57346: No apparent leak, RAM usage stays on ~22Mb after 15+ min. Fast seeks do not increase memory usage.

hrev57352: Very obvious leak, RAM usage ~100Mb after 3min and climbing at ~0.5Mb/sec. Fast seeking increases leakage to ~2Mb/sec.

comment:20 by jackburton, 6 months ago

I suspect we need to call av_frame_unref AFTER we call avcodec_receive_frame().

At least, that's why I understand from here:

https://stackoverflow.com/questions/37907194/audio-decoding-memory-leak-ffmpeg

comment:21 by pulkomandy, 6 months ago

I suspect we need to call av_frame_unref AFTER we call avcodec_receive_frame().

That's already what should happen: the frame can be dereferenced just before decoding the next one, when _DecodeSomeAudioFramesIntoEmptyDecodedDataBuffer is called again.

But something is clearly not working as I think here?

in reply to:  21 comment:22 by jackburton, 6 months ago

Replying to pulkomandy:

I suspect we need to call av_frame_unref AFTER we call avcodec_receive_frame().

That's already what should happen: the frame can be dereferenced just before decoding the next one, when _DecodeSomeAudioFramesIntoEmptyDecodedDataBuffer is called again.

Right, I see now.

in reply to:  21 comment:23 by korli, 6 months ago

Replying to pulkomandy:

But something is clearly not working as I think here?

At least calling memset() then av_frame_unref() doesn't make sense.

comment:24 by waddlesplash, 6 months ago

There's some other problem here though, because it's kernel memory usage that's increasing, not application memory usage. What's up with that?

comment:26 by waddlesplash, 6 months ago

because it's kernel memory usage that's increasing, not application memory usage

At least ProcessController doesn't show kernel memory usage increasing, so maybe there's some problem with the other screenshotted application.

comment:27 by waddlesplash, 6 months ago

Resolution: fixed
Status: newclosed

Fix merged in hrev57382.

Note: See TracTickets for help on using tickets.