Freeing memory used by media player

Hello,

We’re trying to reclaim some of the memory used by nonstreaming mips, which seems incongruously high. We suspect the mp4 videos used in the background of the main menu might be a big factor. To verify this, we made two builds (the first with main menu videos, the second without) and compared their memory usage. As you can see in the graphs below, the build without videos is nearly 900 MiB lighter:

[Image Removed]

This is fine while the player is in the main menu, but the real problem is that we’re continuing to pay for those movies during gameplay. On the graphs, the black line marked with an asterisk indicates the point where the movies are no longer referenced by anything in the game. Any memory used by the movies after that line is pure wasted space.

An initial investigation turned up some dependency chains linking the main menu to gameplay objects, which we removed. However, this gave no significant reduction in memory use, even after forcing garbage collection. To be absolutely sure that we hadn’t missed some stray reference, we ran obj refs name=[video name] on the video objects from within the main menu and during gameplay. It correctly reported the object in the main menu, and reported that the object did not exist during gameplay.

We also investigated the theory that perhaps the media texture was not properly getting cleared. Our media texture is by default set auto clear true. While the main menu is active, auto clear is set false so that the video loops cleanly without black frames. Upon leaving the main menu, we restore auto clear to true and call UMediaPlayer->Close(). Breakpoints show that Close() is always called correctly, and that auto clear is always true when Close() is called.

Do you have any insight into why the videos would continue to incur such a high memory cost even after they’re (to our best knowledge) no longer referenced by living game objects? Is it necessary to delete the media player object entirely between uses, rather than just clearing the playlist and calling Close()?

Any help would be greatly appreciated. I’ve attached a zip with the outputs of obj list from within the main menu and from within gameplay. Please let me know if there’s more information I can provide to help diagnose the issue.

Thank you,

April Martin

[Attachment Removed]

[mention removed]​, here’s the ticket for the issue we’ve been discussing. Thanks!

[Attachment Removed]

Hello April,

it isn’t clear to me from your description which version of UE you are using and on what platform you are measuring.

Also, which media player is being used for playback?

Simply closing the media player may not be enough. If there are any references somewhere the objects may not get garbage collected and linger.

Depending on the platform and the media player implementation being used this could result in a whole media pipeline not being released.

If you are not using the Electra media player I would suggest to enable that plugin and see if it behaves better.

Regards,

Jens

[Attachment Removed]

Hello Jens,

Appreciate the quick response! We’re on UE4.27 and measuring on Switch builds. So far we’ve just been using the default unreal implementation for mp4 videos, so it sounds like trying out the Electra player is the right next move. We’ll get that plugin integrated and see how the dice fall out.

Thanks,

April

[Attachment Removed]

Fantastic news, Jens! Enabling the Electra plugin immediately freed up over 400 MB of unused video memory for us. I can confirm that with Electra once the videos are no longer referenced, they unload from memory.

I’m so grateful there was a quick and easy solution. Thank you for your advice!

- April

[Attachment Removed]

Glad to hear it.

Regards,

Jens

[Attachment Removed]