better memory management for LocalScope