Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6157199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:44:41+00:00 2026-05-23T20:44:41+00:00

Working in Python. I have a function that reads from a queue and creates

  • 0

Working in Python. I have a function that reads from a queue and creates a dictionary based on some of the XML tags in the record read from the queue, and returns this dictionary. I call this function in a loop forever. The dictionary gets reassigned each time. Does the memory previously used by the dictionary get freed at each reassignment, or does it get orphaned and eventually cause memory problems?

def readq():
    qtags = {}
    # Omitted code to read the queue record, get XML string, DOMify it

    qtags['result'] = "Success"
    qtags['call_offer_time'] = get_node_value_by_name(audio_dom, 'call_offer_time')
    # More omitted code to extract the rest of the tags

    return qtags

while signals.sigterm_caught == False:
    tags = readq()
    if tags['result'] == "Empty":
        time.sleep(SLEEP_TIME)
        continue
    # Do stuff with the tags

So when I reassign tags each time in that loop, will the memory used by the previous assignment get freed before being allocated by the new assignment?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T20:44:41+00:00Added an answer on May 23, 2026 at 8:44 pm

    The memory of an object will be freed if it can be proven (from the knowledge the language implementation has at runtime) that it cannot possibly be accessed any more and the garbage collector sees it fit to make a collection. That’s the absolute minimum, and you shouldn’t assume any more. And you usually shouldn’t have to worry about anything more.

    More practically speaking, it may be freed at some point in time between the last reference (where “reference” isn’t limited to names in scope, but can be anything that makes the object reachable) being removed and memory running out. It doesn’t have to be freed by the Python implementation running your code, it may as well leave the memory cleaning to the OS and forget about any finalizers and such. Note that there can be a noticeable delay between the last reference dying and memory usage actually dropping. But as mentioned before, most implementations go out of their way to avoid excessive memory usage if there is garbage to collect.

    Even more practically, you’ll propably be running this on CPython (the reference implementation), which always used and most propably will always use reference counting (augmented with a real GC to handle cyclic references), so unless there’s a cyclic reference (relatively rare and your code doesn’t look like it has them, but can occur e.g. in graph-like structures) it will be freed as soon as the last reference to it is deleted/overwritten. Of course, other implementations aren’t that predictable – PyPy alone has half a dozen different garbage collectors, all but one falling under the above paragraph.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on implementing the MSNP15 protocol in Python. I have verified that
I have a python script start.py that executes well from the command line. There
Working in Python 2.7. I have a dictionary with team names as the keys
I have a working python 2.7 program that calls a DLL. I am trying
I have recently been working with Python using Komodo Edit and other simpler editors
Working with python interactively, it's sometimes necessary to display a result which is some
I'm working on a Python library that interfaces with a web service API. Like
I'm working on a Python package named lehmer that includes a bunch of extension
Working code: Google dictionary lookup via python and beautiful soup -> simply execute and
I've started working on some Android applications and have a question regarding how people

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.