KDE

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • Bad Memory Leak

    7 answers - 765 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    Hello all, not really sure if I
    am right here with my problem, but there is a
    great Memoryleak:
    from qt import *
    app=QApplication([])
    def c():
    print "cc"
    sss=SIGNAL("clicked()")
    while 1:
    d=QDialog()
    b=QPushButton("x",d)
    Q(b,sss,c) #<
    d.exec_loop()
    del b
    del d
    Stay on the escape key, so that many many dialogs
    will be created and deleted.
    Watch used Memory and you will see it increases
    significantly.
    If you comment aut the marked line (Q)
    then the problem does not occur.
    Problem occurs on linux (PyQt-3.5.1-19 (SuSE))
    and on Windows (PyQt-3.11 and PyQt-3.14)
    Greetings, Andre'
    PyKDE mailing list PyKDE (AT) mats (DOT) imk.fraunhofer.de
  • No.1 | | 1206 bytes | |

    06.12.06 06:37:06, Andre Reitz wrote:
    Hello all, not really sure if I
    am right here with my problem, but there is a
    great Memoryleak:


    >from qt import *

    app=QApplication([])
    def c():
    print "cc"

    sss=SIGNAL("clicked()")
    while 1:
    d=QDialog()
    b=QPushButton("x",d)
    Q(b,sss,c) #<
    d.exec_loop()
    del b
    del d

    Stay on the escape key, so that many many dialogs
    will be created and deleted.

    My guess would be that the Python Garbage collector just doesn't run
    often enough to free the memory.

    Note this is python, not C++, del foobar doesn't immediately free the
    memory associated.

    And last but not least: Who on earth creates such code in practice? If
    anybody does he deserves slapping.

    Another thing could be that a reference to the dialog or the pushbutton
    is held "somewhere" by the code that connect() executes. But this is
    sth. Phil has to comment on.

    Problem occurs on linux (PyQt-3.5.1-19 (SuSE))

    3.5.1? Thats more than ancient.

    and on Windows (PyQt-3.11 and PyQt-3.14)

    Well, these are also old versions, PyQt-3.17.

    Andreas
  • No.2 | | 497 bytes | |

    Andre Reitz wrote:

    from qt import *
    app=QApplication([])
    def c():
    print "cc"

    sss=SIGNAL("clicked()")
    while 1:
    d=QDialog()
    b=QPushButton("x",d)
    Q(b,sss,c) #<
    d.exec_loop()
    del b
    del d

    Stay on the escape key, so that many many dialogs
    will be created and deleted.

    Watch used Memory and you will see it increases
    significantly.

    I cannot reproduce it with PyQt 3.16 and SIP 4.4.3.
    It looks like it's been already fixed.
  • No.3 | | 960 bytes | |

    Andreas Pakulat wrote:

    Note this is python, not C++, del foobar doesn't immediately free the
    memory associated.

    That's incorrect. "del foobar" removes a reference; if it's the last
    reference and there are no loops, the memory is immediately collected. Now,
    there are no reference loops at the Python level, so the memory *is*
    collected when the "del" statement is executed.

    Specifically, the first "del b" collected the Python-side instance of the
    push button (the Cside of the pushbutton is owned by the dialog as it's a
    chiled). The second "del d" collects the Python-side instance of the dialog,
    which in turns causes a deletion of the Cside of the dialog (since it has
    no parent, so it's fully owned by Python); the C++ destructor also destroys
    the Cside of the pushbutton. So, after the second "del", all the memory
    is reclaimed, with no need for the Python cyclic GC to kick in.
  • No.4 | | 1880 bytes | |

    Thank you for your quick answer

    Sounds great,
    but memory usage increases continuously.
    Do you have an idea why?
    Is there a bug on C++/SIP side?

    Greetings, Andre'

    Here agaign the test code:

    Please watch Memory usage in Windows Task-Manager
    while holding down the ESCAPE-Key, so you will
    see the mem-usage of the process grows.
    If you remove the Q() line
    it will *not* grow.

    My Problem is that we are developing a large long running
    application in PyQt and we would have plenty of these leaks.

    from qt import *
    app=QApplication([])
    def c():
    print "cc"

    sss=SIGNAL("clicked()")
    while 1:
    d=QDialog()
    b=QPushButton("x",d)
    Q(b,sss,c) #<
    d.exec_loop()
    del b
    del d

    Giovanni Bajo wrote:
    Andreas Pakulat wrote:

    >Note this is python, not C++, del foobar doesn't immediately free the
    >memory associated.


    That's incorrect. "del foobar" removes a reference; if it's the last
    reference and there are no loops, the memory is immediately collected. Now,
    there are no reference loops at the Python level, so the memory *is*
    collected when the "del" statement is executed.

    Specifically, the first "del b" collected the Python-side instance of the
    push button (the Cside of the pushbutton is owned by the dialog as it's a
    chiled). The second "del d" collects the Python-side instance of the dialog,
    which in turns causes a deletion of the Cside of the dialog (since it has
    no parent, so it's fully owned by Python); the C++ destructor also destroys
    the Cside of the pushbutton. So, after the second "del", all the memory
    is reclaimed, with no need for the Python cyclic GC to kick in.

    PyKDE mailing list PyKDE (AT) mats (DOT) imk.fraunhofer.de
  • No.5 | | 632 bytes | |

    06.12.06 16:04:24, Andre Reitz wrote:
    Sounds great,
    but memory usage increases continuously.
    Do you have an idea why?
    Is there a bug on C++/SIP side?

    Maybe, but as Giovanni said, this is not reproducible with
    not-so-ancient PyQt versions, so the solution for you is to upgrade PyQt
    and sip.

    BTW: What happens if you first disconnect the signal and then delete the
    dialog?

    And last but not least: The Windows task tracker is not a sufficient
    tool to find memory leaks. Linux I'd suggest to use valgrind, but I
    don't know which tools are available for Windows.

    Andreas
  • No.6 | | 1176 bytes | |

    ,

    If I disconnect the signal after exec_loop() then
    the leak does not occur.

    I Just found out that in fact in Version 4.1 the leak does
    not occur.

    Greetings and thanks for all

    Andre'

    from qt import *
    app=QApplication([])
    def c():
    print "cc"

    sss=SIGNAL("clicked()")
    while 1:
    d=QDialog()
    b=QPushButton("x",d)
    Q(b,sss,c)
    d.exec_loop()
    Q(b,sss,c) #<<-- no more leak now
    del b
    del d

    Andreas Pakulat wrote:
    06.12.06 16:04:24, Andre Reitz wrote:
    >Sounds great,
    >but memory usage increases continuously.
    >Do you have an idea why?
    >Is there a bug on C++/SIP side?


    Maybe, but as Giovanni said, this is not reproducible with
    not-so-ancient PyQt versions, so the solution for you is to upgrade PyQt
    and sip.

    BTW: What happens if you first disconnect the signal and then delete the
    dialog?

    And last but not least: The Windows task tracker is not a sufficient
    tool to find memory leaks. Linux I'd suggest to use valgrind, but I
    don't know which tools are available for Windows.

    Andreas
  • No.7 | | 210 bytes | |

    Andre Reitz wrote:
    Sounds great,
    but memory usage increases continuously.
    Do you have an idea why?
    Is there a bug on C++/SIP side?
    Did you try updating PyQt and SIP to the latest version?

Re: Bad Memory Leak


max 4000 letters.
Your nickname that display:
In order to stop the spam: 9 + 8 =
QUESTION ON "KDE"

EMSDN.COM