Skip to content

[mypyc] Fix memory leak on property setter call#21095

Open
p-sawicki wants to merge 4 commits intopython:masterfrom
p-sawicki:add-decref-after-property-setter-call
Open

[mypyc] Fix memory leak on property setter call#21095
p-sawicki wants to merge 4 commits intopython:masterfrom
p-sawicki:add-decref-after-property-setter-call

Conversation

@p-sawicki
Copy link
Collaborator

Calling a property setter method results in a memory leak because the setter method internally increfs the passed value and there is no corresponding decref on the caller side. Probably because regular attribute set steals the value so there is no need for a decref there. So add the decref after calling a property setter.

The leak can be observed either by running the updated testPropertySetters test that checks for leaks on master or by manually looking at memory use in top when running a loop like this one:

class Foo():
    def __init__(self) -> None:
        self.attr = "unmodified"

class A:
    def __init__(self) -> None:
        self._foo = Foo()

    @property
    def foo(self) -> Foo:
        return self._foo

    @foo.setter
    def foo(self, val : Foo) -> None:
        self._foo = val

a = A()
while True:
    a.foo = Foo()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant