Improving memory management for releasing object