IF YOUR MEMORY STILL SCALES LINEARLY
You need to periodically clear the root element - for example at the end of each depth one tag (zero-indexed).
Otherwise root element will keep pointers to every child which can consume quite a lot of memory if you are parsing a large file for example 50GB wikipedia dump...