0

I have an app that runs around 400 threads simultaneously. Everything works fine. And the user is able to stop the threads by pressing some button.

To stop a thread, I have implemented a global variable that is set as True when the button is pressed. The threads checks for this variable regularly. If ON, return.

return works fine for me as a way of stopping the thread: I can see no more output to the user from the threads. However, when I check in the task manager memory I find the following:

  • Before starting the threads, Python takes up around 64MB RAM

  • After starting the threads, Python takes up around 700MB RAM

  • After stopping the threads as above, Python takes around 600MB RAM but it never goes back to 64MB RAM

I think this is a garbage collection problem. Maybe using return is a bad idea. How can I solve this?

Update:

The App is a Tkinter App, and the threads runs in a separate TopLevel.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
AhmedWas
  • 1,205
  • 3
  • 23
  • 38
  • You mean *"After stopping the threads"* **AND** the app == main is still running? – stovfl Mar 05 '19 at 10:01
  • yes, the (main) app is still running – AhmedWas Mar 05 '19 at 11:29
  • *"yes, the (main) app is still running"*: Therfore all `global` or referenced objects still exists. You have to use `del ` to get the objects deleted. But keep in mind, objects which are referenced are still in memory. Read [how-can-i-explicitly-free-memory-in-python](https://stackoverflow.com/questions/1316767/how-can-i-explicitly-free-memory-in-python) – stovfl Mar 05 '19 at 11:56
  • Thank you for your reply. Yes, ´del´ didn't help much. So how can I delete objects which are refrenced in memory? – AhmedWas Mar 06 '19 at 13:37
  • *"delete objects which are refrenced in memory?"*: Delete the reference also. – stovfl Mar 06 '19 at 13:51
  • Relevant [Weak References in python](https://stackoverflow.com/a/9908216/7414759) – stovfl Mar 06 '19 at 14:39
  • Thanks, I'll have a look – AhmedWas Mar 06 '19 at 14:39

0 Answers0