2

I have a multithreaded PyQt application that is leaking memory. All the functions that leak memory are worker threads, and I'm wondering if there's something fundamentally wrong with my approach.

When the main application starts, the various worker thread instances are created from the thread classes, but they are not initially started.

When functions run that require a worker thread, the thread is initialized (data and parameters are passed from the main function, and variables are reset from with in the worker instance), and then the thread is started. The worker thread does its business, then completes, but is never formally deleted.

If the function is called again, then again the thread instance is initialized, started, runs, stops, etc...

Because the threads can be called to run again and again, I never saw the need to formally delete them. I originally figured that the same variables were just get re-used, but now I'm wondering if I was mistaken.

Does this sound like the cause of my memory leak? Should I be deleting the threads when they complete even if they're going to be called again?

If this is the root of my problem, can someone point me to a code example of how to handle the thread deleting process properly? (If it matters, I'm using PyQt 4.11.3, Qt 4.8.6, and Python 3.4.3)

OwlPenn
  • 81
  • 9
  • 3
    You should post the simplest version of your code that still exhibits this behaviour to make your question clearer. – 101 Apr 21 '15 at 23:47
  • Like figs said, you may want to post an example of your code - what kinds of objects and methods are being moved to your new threads? Are you using QThread correctly, or are you using Python's threading library? Without code, it's hard to diagnose A) what the memory leak is, and B) if it's *actually* a memory leak! Are you experiencing program crashes? Are you using QThreads correctly? Check out [this question](https://stackoverflow.com/questions/20324804/how-to-use-qthread-correctly-in-pyqt-with-movetothread/30179380) – Matthew Runchey Jun 04 '15 at 01:24

0 Answers0