Skip to content

How to properly update the menu without leaking memory? #216

@israelsucks

Description

@israelsucks

Hello,

I've spotted my app which updates its menu regularly reaches multiple GB's of memory over time.

Here is an example code similar to my code's logic, which uses exaggerated values for quick demonstration purposes:

#!/usr/bin/env python3

import rumps
import time

testinterval=0.1

class AwesomeStatusBarApp(rumps.App):

    def __init__(self):
        super(AwesomeStatusBarApp, self).__init__("myapp")
        self.menu = [f"hello"]

    @rumps.timer(testinterval)
    def sayhi(self, _):
        mylist = []
        for i in range(1000):
            mylist += ['time', str(time.time())*10, None]

        # reset menu
        self.menu.clear()

        self.menu = mylist # or self.menu.update(mylist), doesn't matter

if __name__ == "__main__":
    AwesomeStatusBarApp().run()

If you look at Activity Monitor, you'll see its memory grows indefinitely. I've also tried iterating over menu keys() and deleting them but didn't fix the leak.

Am I doing something wrong or is it the rumps which leaks memory under the hood?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions