Check if memory is valid before use it.