memory management refactoring #12701