This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
工具/软件:TI-RTOS
您好!
我使用 malloc()为变量分配了动态内存。
然后、我想在使用后释放存储器。 所以我使用了 free()。 但是、在这之后、当我尝试访问变量时、我仍然会获得该值、但它不会被释放。
char * temp = malloc (10 * sizeof (char));
。 这里有一些代码用于为 temp 分配值。。
免费(临时);
printf (temp)->在这里、它仍然显示该值
FREE()当时是否不起作用?
此致、
Shyam
您好!
这是正确的行为。 对 free()的调用将相关的内存块标记为在堆内部未使用,但 free 不会尝试使您在应用程序中使用的指针无效,也不会以某种方式清除正在释放的内存块。 由程序员来使指针无效。 如果您的应用程序对释放的内存块中的内容敏感、那么用户也有责任清理它。
希望这对您有所帮助。