Kodi Community Forum
Script has left several classes in memory... - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32)
+--- Forum: Add-ons (https://forum.kodi.tv/forumdisplay.php?fid=26)
+--- Thread: Script has left several classes in memory... (/showthread.php?tid=307508)



Script has left several classes in memory... - el_Paraguayo - 2017-02-19

I'm getting this warning when my script exits:
Code:
09:39:06.525 T:140467688380160 WARNING: CPythonInvoker(7, /home/anto/.kodi/addons/script.squeezeinfo/main.py): the python script "/home/anto/.kodi/addons/script.squeezeinfo/main.py" has left several classes in memory that we couldn't clean up. The classes include: N9XBMCAddon7xbmcgui10DialogBusyE
The script uses WindowXML and I make sure I use "del" when the window closes.

I can also see XBMCAddon and xbmgui DIalogBusy in there. I have created an xbmcaddon instance to get settings etc. but haven't used DialogBusy at all.

Do I need to delete the xbmcaddon instance when I exit too?

Any other ideas how to get rid of this message.

My code is here: https://github.com/elParaguayo/script.squeezeinfo
and the "del" methods can be seen in this commit: https://github.com/elParaguayo/script.squeezeinfo/commit/5d403b18a90e3cd339511a7d2c814c1933097473


RE: Script has left several classes in memory... - User 342716 - 2017-02-19

Have you tried self.player = None instead of del self.player?

Not sure if it will work, but i know on my script i had the same issue and it was due to using a Player in the same fashion as you.
Since this seems to be built for only kodi 17+ I was not able to install to test


RE: Script has left several classes in memory... - el_Paraguayo - 2017-02-19

I can try it, but that is not a kodi Player object. It's a very simple class to get info on a squeezeplayer attached to a Logitech Media Server.

You'd need the server to test the script. You can downgrade the dependency but the skin file would look ugly because the conditional visibilty tests i use only work in Krypton.


RE: Script has left several classes in memory... - User 342716 - 2017-02-19

(2017-02-19, 17:58)el_Paraguayo Wrote: I can try it, but that is not a kodi Player object. It's a very simple class to get info on a squeezeplayer attached to a Logitech Media Server.

You'd need the server to test the script. You can downgrade the dependency but the skin file would look ugly because the conditional visibility tests i use only work in Krypton.

I don't think it matters if it is a player class. This i just where i discovered it. I have had the issue referencing any class over even custom classes. I can not specifically say this is your cause, but it was the only one i saw referencing a class .


RE: Script has left several classes in memory... - Roman_V_M - 2017-02-19

This was already discussed some time ago. My hypothesis is that reference counting for Kodi classes exposed to Python via SWIG is somehow broken preventing them to be cleaned by Python's Garbage Collector.
As for del operator, despite what the name suggests, by default (unless overloaded) it does not delete an object but decreases its reference counter by 1. Normally, it is enough for the object to be cleaned by the GC, but if the reference counter is screwed simple applying del won't help.

Bottom line: nothing can be done at Python level.


RE: Script has left several classes in memory... - el_Paraguayo - 2017-02-19

Fair enough - I'll just ignore it!

Thanks to both of you for your comments.


RE: Script has left several classes in memory... - boogiepop - 2017-02-20

i faced similar problem when a c level object is referenced to pythonic object, gc would not be able to clean it up. ie:

Code:
import xbmcgui
class myclass(object):
    def __init__(self):
        self.dia = xbmcgui.Dialog()

when script ends, gc collects myclass but leaves xmcgui.Dialog as garbage, after several runs may be a day os so, it would lead kodi to crash.

i had worked around by not referencing kodi c objects to my pythonic objects.

hope that helps