Python Forum
Is it safe to use outside a class created inside the function? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Is it safe to use outside a class created inside the function? (/thread-7190.html)



Is it safe to use outside a class created inside the function? - oneroslavsky - Dec-27-2017

Let you pass the list of classes as an argument to your function. Let also, inside this function you create a class and append it to the list in question. When you return from your function, the memory used for the function is cleaned. Is it safe still to use the class created inside the function and passed along the list? I think the answer is in affirmative still ...


RE: Is it safe to use outside a class created inside the function? - Windspar - Dec-27-2017

Of course you can. But don't forget the KISS philosophy.
Simple is better then complex.


RE: Is it safe to use outside a class created inside the function? - mpd - Dec-27-2017

That's fine. Python uses "reference counting" to keep track of objects. The list has a reference to the newly created class so its memory has not been cleaned up(aka "garbage collected") even after returning from the function.