Small memory/easier gc related fixes
Merge pull request #6190 from ctomc/mem-leak

Small memory/easier gc related fixes