TreeDict: rewrite to C++, part 2: immutable TreeDict (leaking mem)