Python Forum
Is it safe to use outside a class created inside the function?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is it safe to use outside a class created inside the function?
#1
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 ...
Reply
#2
Of course you can. But don't forget the KISS philosophy.
Simple is better then complex.
99 percent of computer problems exists between chair and keyboard.
Reply
#3
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  not able to call the variable inside the if/elif function mareeswaran 3 1,532 Feb-09-2025, 04:27 PM
Last Post: mareeswaran
  The function of double underscore back and front in a class function name? Pedroski55 9 3,636 Feb-19-2024, 03:51 PM
Last Post: deanhystad
  When is it safe to compare (==) two floats? Radical 4 4,494 Nov-12-2023, 11:53 AM
Last Post: PyDan
  with open context inside of a recursive function billykid999 1 1,962 May-23-2023, 02:37 AM
Last Post: deanhystad
  How do I call sys.argv list inside a function, from the CLI? billykid999 3 2,895 May-02-2023, 08:40 AM
Last Post: Gribouillis
  TimeOut a function in a class ? Armandito 1 3,190 Apr-25-2022, 04:51 PM
Last Post: Gribouillis
  Calling a class from a function jc4d 5 4,049 Dec-17-2021, 09:04 PM
Last Post: ndc85430
  a function common to methods of a class Skaperen 7 5,137 Oct-04-2021, 07:07 PM
Last Post: Skaperen
  Tuple generator, and function/class syntax quazirfan 3 9,608 Aug-10-2021, 09:32 AM
Last Post: buran
  How to make global list inside function CHANKC 6 5,248 Nov-26-2020, 08:05 AM
Last Post: CHANKC

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020