Question

Provide example source code in Python that the standard garbage collection features will fail to collect automatically.

Provide example source code in Python that the standard garbage collection features will fail to collect automatically.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer: Standard garbage collection features will fail to collect automatically when a reference cycle is created in

the program .

Reference cycle means an object  refers to itself.

Source Code where standard garbage collection features will fail to collect automatically.

  

def cycle():

# create a list x
x = [ ]  

# A reference cycle is created
# here x contains reference to itself  
x.append(x)

cycle()

Here ,an object x which refers to itself, the object x will not automatically be freed when the function returns. This will cause the memory that x is using to be held onto until the Python garbage collector is invoked manually .

Add a comment
Know the answer?
Add Answer to:
Provide example source code in Python that the standard garbage collection features will fail to collect automatically.
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT