MAINT simpler memory management for trees (+test)