如何释放已用于C中变量的内存? [英] How to release the memory that has been used for a variable in C?

查看:94
本文介绍了如何释放已用于C中变量的内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何释放C中用于变量(例如长字符串)的内存?

How can i release the memory that I used for a variable (e.g. a long string) in C?

推荐答案

假定您是动态分配内存的(使用malloc或其他内存分配器),则可以使用free释放它.如果内存是静态分配的,则无法释放它.

Assuming that you allocated the memory dynamically (using malloc or another memory allocator) you free it using free. If the memory was statically allocated, you can't free it.

这篇关于如何释放已用于C中变量的内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆