Skip to content

Avoid free() on quit #12294

Closed
Closed
@mrnoname1000

Description

As far as I can tell without debugging, mpv decides to free all the malloc'd memory before quitting. This wastes CPU cycles since it would happen anyway when the process exits. I have had mpv take several minutes to quit because most of its memory was inactive and written to swap, which it has to read back to free. The desired behavior can be observed with a kill -9 <mpv pid> as even if mpv has gigabytes in swap, it will still terminate immediately.

It still might be necessary to release some resources before quit, but free() can be safely omitted. I'm not familiar with the codebase but maybe a global variable in the mpv executable would be fine to track if free() is necessary. I don't imagine this would apply to libmpv unless it can call exit() as well.

Expected behavior of the wanted feature

mpv quits immediately with minimal calls to free().

Alternative behavior of the wanted feature

Currently? mpv frees all blocks received by malloc/calloc then quits.

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions