Q:

Python destroying content to save memory

I have a class to get a webpage's html and do some things with it
import requests

class A(object):
    def __init__(self, url):
        self.r = requests.get(url)
        self.html = self.r.text
        #other things

class B(A):
    def __init__(self,url):
        super(B,self).__init__(url)
        #other things

I am going to instantiate this class hundreds of thousands of times, like so
for url in many_urls:
    page = B(url)
    #other things

how can I make sure that the content like page.html and other attributes get deleted and aren't kept in memory to slow it down?

A:

The html will be held in memory for as long as the object that references it exists. 
If your for loop does not assign the B object to any other variable, then each time you re-assign page the previously created B object will become eligible for garbage collection, and the html will be removed from memory at the same time.
If you are retaining references to each of your B objects you will slowly fill up your memory, but if you allow them to be garbage collected you should be fine.

