Improved free memory detection