improved free so that it decreases the heap size when possible