幾乎沒有那個程序員會有意使用釋放的內存, 但是意外的使用卻是常有的事。 考慮下面釋放單鏈表的正確代碼:
struct list *listp, *nextp; for(listp = base; listp != NULL; listp = nextp) { nextp = listp->next; free(listp); }請注意如果在循環表達式中沒有使用臨時變量 nextp, 而使用 listp = listp-> next會產生什麼惡劣後果。
參考資料: [K&R2, Sec. 7.8.5 p. 167]; [ISO, Sec. 7.10.3]; [Rationale, Sec. 4.10.3.2]; [H&S, Sec. 16.2 p. 387]; [CT&P, Sec. 7.10 p. 95]。
翻譯朱群英、孫雲, LaTeX2HTML 編譯 朱群英 (2005-06-23)