[英]Free for consistent dynamically allocated char pointers?
我有一個結構,其中包含一堆char指針,其值在程序的整個生命周期內都使用。 大多數在每次迭代時都會被覆蓋。
除了程序退出外,是否還應在任何時候釋放這些值? 在用strdup("new value")
覆蓋char指針中的值之前,應該釋放它嗎?
@ some-programmer-dude是正確的,如果您的程序像服務器一樣工作,則會出現內存泄漏而沒有空閑。
順便說一句,無論您是否調用free(),程序退出后都會釋放所有內存。
您已經知道答案了。 我只是提供更多信息和參考。
POSIX標准strdup的手冊頁。
開始了,
The strdup() function returns a pointer to a new string which is a duplicate of the string s. Memory for the new string is obtained with malloc(3), and can be freed with free(3).
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.