Skip to content

Memory leak every new instance of Display() #136

@leinardi

Description

@leinardi

I found this issue after I got a report that GWE was using 1.6 GB after several hours of execution (normally it should be around 100MB).

The problem seems to be that every time a new instance of display.Display() is created, a new type for all the resource classes is generated:

self.display.resource_classes[class_name] = type(origcls.__name__,

This is a problem if, like in GWE, you want to periodically use an extension and a new instance of Display is created and closed after each invocation.

A simple reproduction script can be found here:
https://github.com/leinardi/python-xlib/blob/memory-leak/leak.py

Top 1 lines
#1: <frozen importlib._bootstrap_external>:487: 398.2 KiB
1903 other: 984.7 KiB
Total allocated size: 1382.9 KiB
Top 1 lines
#1: Xlib/display.py:137: 600.6 KiB
    dictionary)
1956 other: 2485.5 KiB
Total allocated size: 3086.1 KiB
Top 1 lines
#1: Xlib/display.py:137: 1435.7 KiB
    dictionary)
1960 other: 3467.0 KiB
Total allocated size: 4902.7 KiB
Top 1 lines
#1: Xlib/display.py:137: 2505.5 KiB
    dictionary)
1961 other: 4612.2 KiB
Total allocated size: 7117.7 KiB
Top 1 lines
#1: Xlib/display.py:137: 3809.2 KiB
    dictionary)
1963 other: 3137.9 KiB
Total allocated size: 6947.1 KiB
Top 1 lines
#1: Xlib/display.py:137: 5347.5 KiB
    dictionary)
1963 other: 3597.0 KiB
Total allocated size: 8944.5 KiB

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions