Fix memory recycling problems