Terrance/SkPy

Memory leak

Closed this issue · 3 comments

I'm running script in multi-threading and use sessions with session.close(). As the script runs, I see how memory consumption grows until it's over. As far as I understand, this issue is related to requests.

I've tried clearing memory via gc.collect() but it doesn't help.

Can anyone know how to fix this?

use sessions with session.close()

What does this mean? Are you creating many Skype instances and closing their sessions after performing a single action? You should only need one instance with a single persistent Skype connection for the lifetime of your program.

Most objects from the server (users, chats, messages etc.) all hold a reference to the owning Skype instance so that further API requests can be made (e.g. to retrieve the author of a message), so if you're dropping a Skype instance but holding on to anything it provided you with, it'll live on.

No, I create only 1 Skype instance in one thread, work with the Skype class and close the session at the end of the thread. If the session is not closed, then the memory leaks even more.

Also, I have to delete the skype object itself at the end of the thread. Like this:

sk = Skype(...)
...
del sk

In this scenario, the memory leak is reduced. But all the same, the memory continues leak.

I've left an event loop running for the last few days, sent it a few messages, and it doesn't seem to be growing in memory, so it's hard to say what's going on without seeing your code.

I'm still unclear what you're doing with the threads -- you should avoid creating a Skype session in each thread as you're liable to get rate limited (even if you reuse the session with the token file; there are also limits e.g. on subscriptions, when you start listening for events). IIRC requests is not thread-safe so you can't just share the Skype instance, but consider a single instance and a queue for accepting actions from other threads.