Python Forum
quick question about deleting an object from memory
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
quick question about deleting an object from memory
#2
Once there are no references to an object, the garbage collector will eventually purge those objects from memory.

In practice, that means using objects and functions, so there's an extremely small number of things that actually reference any memory.  To use your example, it'd be something like: 
if level_complete:
    sprites_in_level = []
    # any sprites that were loaded in that level are now not referenced, and will be garbage collected

    # load the sprites needed for the new level
    current_level += 1
    for sprite in LevelSprites(current_level):
        sprites_in_level.append(sprite.load())
Reply


Messages In This Thread
RE: quick question about deleting an object from memory - by nilamo - Nov-10-2016, 09:18 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Getting an error while trying to process data, low memory when memory is not low? bkeith12 0 656 Dec-20-2024, 03:06 PM
Last Post: bkeith12
  Quick question/help regarding my variable Extra 5 2,802 May-06-2022, 12:01 AM
Last Post: Extra
  Quick Question about Dictionaries Extra 6 3,109 Apr-29-2022, 08:34 PM
Last Post: Extra
  Memory Location, Object Attributes and how to use them Meld51 1 2,351 Aug-22-2021, 01:22 PM
Last Post: Yoriz
  finding and deleting json object GrahamL 1 6,078 Dec-10-2020, 04:11 PM
Last Post: bowlofred
  quick question/excel+python zarize 1 2,976 Dec-06-2019, 05:38 PM
Last Post: Larz60+
  opencv memory question djf123 1 5,835 May-26-2019, 11:03 AM
Last Post: heiner55
  A quick question teczone 4 4,168 Sep-06-2018, 03:44 PM
Last Post: snippsat
  Completely new to coding - quick question Oster22 1 3,412 Jun-19-2018, 08:42 PM
Last Post: Larz60+
  Quick help! Ellisrb 2 3,691 May-02-2018, 11:21 AM
Last Post: ThiefOfTime

Forum Jump:

User Panel Messages

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