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
  The function of double underscore back and front in a class function name? Pedroski55 9 676 Feb-19-2024, 03:51 PM
Last Post: deanhystad
  When is it safe to compare (==) two floats? Radical 4 737 Nov-12-2023, 11:53 AM
Last Post: PyDan
  with open context inside of a recursive function billykid999 1 584 May-23-2023, 02:37 AM
Last Post: deanhystad
  How do I call sys.argv list inside a function, from the CLI? billykid999 3 796 May-02-2023, 08:40 AM
Last Post: Gribouillis
  TimeOut a function in a class ? Armandito 1 1,661 Apr-25-2022, 04:51 PM
Last Post: Gribouillis
  Calling a class from a function jc4d 5 1,830 Dec-17-2021, 09:04 PM
Last Post: ndc85430
  a function common to methods of a class Skaperen 7 2,628 Oct-04-2021, 07:07 PM
Last Post: Skaperen
  Tuple generator, and function/class syntax quazirfan 3 3,895 Aug-10-2021, 09:32 AM
Last Post: buran
  How to make global list inside function CHANKC 6 3,120 Nov-26-2020, 08:05 AM
Last Post: CHANKC
  Parameters aren't seen inside function Sancho_Pansa 8 2,946 Oct-27-2020, 07:52 AM
Last Post: Sancho_Pansa

Forum Jump:

User Panel Messages

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