'https://stackoverflow.com/questions/12160418/why-is-lxml-etree-iterparse-eating-up-all-my-memory'

def test_iterparse_remove_unused(self):

    raise SkipTest('This    method    is    awful    in    terms    of    memory    usage,    even    with    the    calls    to    elem.clear()    which    I    hoped    would    improve    it.    This    solution    also    has    the    issue    of    being    awfully    slow.')
    def fast_iter(context, func, *args, **kwargs):
        "\n                                                http://lxml.de/parsing.html#modifying-the-tree\n                                                Based    on    Liza    Daly's    fast_iter\n                                                http://www.ibm.com/developerworks/xml/library/x-hiperfparse/\n                                                See    also    http://effbot.org/zone/element-iterparse.htm\n                                                "
        for (event, elem) in context:
            func(elem, *args, **kwargs)
            elem.clear()
            while (elem.getprevious() is not None):
                del elem.getparent()[0]
        del context
    phishtank_db_fd = file(PHISHTANK_DB)
    def process_element(elem):
        pass
    context = etree.iterparse(phishtank_db_fd, events=('end',), tag='entry', html=True)
    fast_iter(context, process_element)
