Should I use garbage collect?

64 views
Skip to first unread message

Rudi Hammad

unread,
Apr 25, 2017, 9:19:25 AM4/25/17
to Python Programming for Autodesk Maya
Hello,
I am developing a rig builder tool for the studio that is quite heavy, and after running the UI I checked the garbage collection and I get a result of gc.collect() -->322. If I run the UI 3 times, then the gc.collect() -->955

I don´t know much about memory performance so I wonder if  this happening because my code is not clean enough or if this normal while programming a code with a lot a variables and objects?
Should I just do gc.collect() at the end of the script to clean things up?

thank you

David Moulder

unread,
Apr 25, 2017, 9:53:59 AM4/25/17
to python_inside_maya
You shouldn't need to gc.collect() in python.  When the instances reference count goes to 0 then at some point in the future pythons garbage collection will kick in.  If you are holding onto references then this could account for the memory bloat.  But if you are patient you might also see python clean up after itself.

How are you building the UI?  PySide?  Are you using a lot of globals?  How are you closing and opening the UI?  Are you parenting all you widgets into the UI?

-Dave


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/9bc3d18a-5f39-44bf-948c-22c7d7746a86%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Rudi Hammad

unread,
Apr 25, 2017, 12:17:47 PM4/25/17
to Python Programming for Autodesk Maya
Hi,
I am using Pyside. I don´t use any globals. I open the ui with .show(). And I close with cmds.deleteUI() if the windows exists.
Not all the widgets are parented to the UI, because that UI have widgets like buttons that launch other smallet UIs.

R

Justin Israel

unread,
Apr 25, 2017, 3:42:23 PM4/25/17
to Python Programming for Autodesk Maya


On Wed, Apr 26, 2017, 4:17 AM Rudi Hammad <rudih...@gmail.com> wrote:
Hi,
I am using Pyside. I don´t use any globals. I open the ui with .show(). And I close with cmds.deleteUI() if the windows exists.
Not all the widgets are parented to the UI, because that UI have widgets like buttons that launch other smallet UIs.

Are toy parenting your top level window to the Maya Main window? It is a common error that I see people doing, where they create windows that are parented to Maya and then let the reference go. When users close them, they remain alive. 

You could tell your top level window to delete itself when a user closed it

window.setAttribute(QtCore.Qt.WA_DeleteOnClose)

But you did say you are deleting previous instances when you launch a new one, and garbage still continues to increase? That would imply you have something holding onto references and/or your delete is not finding the previous window as you expect. 



R


El martes, 25 de abril de 2017, 14:53:59 (UTC+1), thirstydevil escribió:
You shouldn't need to gc.collect() in python.  When the instances reference count goes to 0 then at some point in the future pythons garbage collection will kick in.  If you are holding onto references then this could account for the memory bloat.  But if you are patient you might also see python clean up after itself.

How are you building the UI?  PySide?  Are you using a lot of globals?  How are you closing and opening the UI?  Are you parenting all you widgets into the UI?

-Dave

On Tue, Apr 25, 2017 at 2:19 PM, Rudi Hammad <rudih...@gmail.com> wrote:
Hello,
I am developing a rig builder tool for the studio that is quite heavy, and after running the UI I checked the garbage collection and I get a result of gc.collect() -->322. If I run the UI 3 times, then the gc.collect() -->955

I don´t know much about memory performance so I wonder if  this happening because my code is not clean enough or if this normal while programming a code with a lot a variables and objects?
Should I just do gc.collect() at the end of the script to clean things up?

thank you

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.



--
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/818f6def-71a8-4b51-b40e-9860dd6db5e1%40googlegroups.com.

Rudi Hammad

unread,
Apr 25, 2017, 5:35:12 PM4/25/17
to Python Programming for Autodesk Maya
I do something like

def maya_main_window():

     main_window_ptr = OpenMayaUI.MQtUtil.mainWindow()

     return wrapInstance(long(main_window_ptr), QtGui.QWidget)


class TestTool(QtGui.QDialog):


def __init__(self, parent=maya_main_window()):

    super(TestTool, self).__init__(parent)


I´ll tomorrow at work  window.setAttribute(QtCore.Qt.WA_DeleteOnClose)

R

El martes, 25 de abril de 2017, 20:42:23 (UTC+1), Justin Israel escribió:


On Wed, Apr 26, 2017, 4:17 AM Rudi Hammad <rudih...@gmail.com> wrote:
Hi,
I am using Pyside. I don´t use any globals. I open the ui with .show(). And I close with cmds.deleteUI() if the windows exists.
Not all the widgets are parented to the UI, because that UI have widgets like buttons that launch other smallet UIs.

Are toy parenting your top level window to the Maya Main window? It is a common error that I see people doing, where they create windows that are parented to Maya and then let the reference go. When users close them, they remain alive. 

You could tell your top level window to delete itself when a user closed it

window.setAttribute(QtCore.Qt.WA_DeleteOnClose)

But you did say you are deleting previous instances when you launch a new one, and garbage still continues to increase? That would imply you have something holding onto references and/or your delete is not finding the previous window as you expect. 



R


El martes, 25 de abril de 2017, 14:53:59 (UTC+1), thirstydevil escribió:
You shouldn't need to gc.collect() in python.  When the instances reference count goes to 0 then at some point in the future pythons garbage collection will kick in.  If you are holding onto references then this could account for the memory bloat.  But if you are patient you might also see python clean up after itself.

How are you building the UI?  PySide?  Are you using a lot of globals?  How are you closing and opening the UI?  Are you parenting all you widgets into the UI?

-Dave

On Tue, Apr 25, 2017 at 2:19 PM, Rudi Hammad <rudih...@gmail.com> wrote:
Hello,
I am developing a rig builder tool for the studio that is quite heavy, and after running the UI I checked the garbage collection and I get a result of gc.collect() -->322. If I run the UI 3 times, then the gc.collect() -->955

I don´t know much about memory performance so I wonder if  this happening because my code is not clean enough or if this normal while programming a code with a lot a variables and objects?
Should I just do gc.collect() at the end of the script to clean things up?

thank you

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.



--
David Moulder
Technical Animator / Artist

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

Rudi Hammad

unread,
Apr 25, 2017, 5:36:11 PM4/25/17
to Python Programming for Autodesk Maya
upss...sorry about that code copy paste

Justin Israel

unread,
Apr 25, 2017, 5:48:15 PM4/25/17
to python_in...@googlegroups.com
On Wed, Apr 26, 2017 at 9:35 AM Rudi Hammad <rudih...@gmail.com> wrote:
I do something like

def maya_main_window():

     main_window_ptr = OpenMayaUI.MQtUtil.mainWindow()

     return wrapInstance(long(main_window_ptr), QtGui.QWidget)


class TestTool(QtGui.QDialog):


def __init__(self, parent=maya_main_window()):

    super(TestTool, self).__init__(parent)



Yes, this is the case to which I was referring. Because this tool is parented to the main window, if you simply create it, show it, and let the python reference go, it will hang around when the user closes it. This is a very common thing I have seen, where there are lots of small tool windows written by lots of TDs. And people are popping them up and closing them all day and they just build up in memory for the life of the Maya session. It is also a common bug with QMenu and QAction. 

 
I´ll tomorrow at work  window.setAttribute(QtCore.Qt.WA_DeleteOnClose)

R
El martes, 25 de abril de 2017, 20:42:23 (UTC+1), Justin Israel escribió:


On Wed, Apr 26, 2017, 4:17 AM Rudi Hammad <rudih...@gmail.com> wrote:
Hi,
I am using Pyside. I don´t use any globals. I open the ui with .show(). And I close with cmds.deleteUI() if the windows exists.
Not all the widgets are parented to the UI, because that UI have widgets like buttons that launch other smallet UIs.

Are toy parenting your top level window to the Maya Main window? It is a common error that I see people doing, where they create windows that are parented to Maya and then let the reference go. When users close them, they remain alive. 

You could tell your top level window to delete itself when a user closed it

window.setAttribute(QtCore.Qt.WA_DeleteOnClose)

But you did say you are deleting previous instances when you launch a new one, and garbage still continues to increase? That would imply you have something holding onto references and/or your delete is not finding the previous window as you expect. 



R


El martes, 25 de abril de 2017, 14:53:59 (UTC+1), thirstydevil escribió:
You shouldn't need to gc.collect() in python.  When the instances reference count goes to 0 then at some point in the future pythons garbage collection will kick in.  If you are holding onto references then this could account for the memory bloat.  But if you are patient you might also see python clean up after itself.

How are you building the UI?  PySide?  Are you using a lot of globals?  How are you closing and opening the UI?  Are you parenting all you widgets into the UI?

-Dave

On Tue, Apr 25, 2017 at 2:19 PM, Rudi Hammad <rudih...@gmail.com> wrote:
Hello,
I am developing a rig builder tool for the studio that is quite heavy, and after running the UI I checked the garbage collection and I get a result of gc.collect() -->322. If I run the UI 3 times, then the gc.collect() -->955

I don´t know much about memory performance so I wonder if  this happening because my code is not clean enough or if this normal while programming a code with a lot a variables and objects?
Should I just do gc.collect() at the end of the script to clean things up?

thank you

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.



--
David Moulder
Technical Animator / Artist

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/8f9ad9df-6236-41bb-828a-6aa85a2538b3%40googlegroups.com.

Rudi Hammad

unread,
Apr 26, 2017, 5:35:36 AM4/26/17
to Python Programming for Autodesk Maya
Great, I'll clean that up after closing it. Thank you.
Reply all
Reply to author
Forward
0 new messages