free
will deallocate the memory that p
points to - simply assigning it to NULL
will not (and thus you will have a memory leak).
It is worth mentioning that it is good practice to assign your pointer to NULL
AFTER the call to free
, as this will prevent you from accidentally trying to access the freed memory (which is still possible, but absolutely should not be done).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…