free 释放内存
http://www.cplusplus.com/reference/cstdlib/free/
free
void free (void* ptr);
A block of memory previously allocated by a call to malloc, calloc or realloc is deallocated, making it available again for further allocations.
If ptr does not point to a block of memory allocated with the above functions, it causes undefined behavior.
If ptr is a null pointer, the function does nothing.
Notice that this function does not change the value of ptr itself, hence it still points to the same (now invalid) location.
Parameters
Return Value
none
Example
|
|
This program has no output. It just demonstrates some ways to allocate and free dynamic memory using the C stdlibfunctions.
Data races
Only the storage referenced by ptr is modified. No other storage locations are accessed by the call.
If the function releases a unit of storage that is reused by a call to allocation functions (such as calloc or malloc), the functions are synchronized in such a way that the deallocation happens entirely before the next allocation.
Exceptions (C++)
No-throw guarantee: this function never throws exceptions.
If ptr does not point to a memory block previously allocated with malloc, calloc or realloc, and is not a null pointer, it causes undefined behavior.
See also
- malloc
- Allocate memory block (function )
- calloc
- Allocate and zero-initialize array (function )
- realloc
- Reallocate memory block (function )
free 释放内存的更多相关文章
- CentOS7清理yum缓存和释放内存方法
清理yum缓存 清理yum缓存使用yum clean 命令,yum clean 的参数有headers, packages, metadata, dbcache, plugins, expire-ca ...
- 在dll里malloc/new/cvCreate分配内存,在exe里free/Releases释放内存时会出错。
写了个程序,在DLL中用malloc分配了一块内存,但是在exe程序中释放,结果程序crash,原因就是:其原因可能是堆被损坏,这也说明 TestMySticker.exe 中或它所加载的任何 DLL ...
- PHP unset()函数销毁变量 但没有实现释放内存
<?PHP $a = "hello";$b = &$a;unset( $b );echo $a; // 输出 helloecho $b; // 报错$b = &quo ...
- PHP unset销毁变量并释放内存
PHP的unset()函数用来清除.销毁变量,不用的变量,我们可以用unset()将它销毁.但是某些时候,用unset()却无法达到销毁变量占用的内存!我们先看一个例子: <?php $s=st ...
- vector容器删除某些元素且释放内存
1,size和capacity size: 指目前容器中实际有多少元素,对应的resize(size_type)会在容器尾添加或删除一些元素,来调整容器中实际的内容,使容器达到指定的大小. capac ...
- android回收AnimationDrawable动画的每一帧的图片资源,而释放内存
回收每一帧的图片,释放内存资源 private void tryRecycleAnimationDrawable(AnimationDrawable animationDrawables) { if ...
- Linux手动释放内存
手动释放内存 1.sync将内存中的缓存写入磁盘 2. to free pagecache, use echo 1 > /proc/sys/vm/drop_caches; to f ...
- redis采用tcmalloc导致无法释放内存的问题
from:http://wangneng-168.iteye.com/blog/2100379 redis使用tcmalloc管理内存,当删除了redis的key后,通过redis的info命令查看内 ...
- python里的del变量无法立刻释放内存的解决办法
最近在python开发的时候,用到了一些很占用内存的操作,导致后续程序执行很慢甚至无法执行.探索了一下,最终解决了这个问题. 截图解释: python变量占用了内存,仅仅通过del变量的方式,只是让这 ...
- /MT、/MD编译选项,以及可能引起在不同堆中申请、释放内存的问题
一.MD(d).MT(d)编译选项的区别 1.编译选项的位置 以VS2005为例,这样子打开: 1) 打开项目的Property Pages对话框 2) 点击左侧C/C ...
随机推荐
- Objective-C语法之动态类型(isKindOfClass, isMemberOfClass,id)等
对象在运行时获取其类型的能力称为内省.内省可以有多种方法实现. 判断对象类型 -(BOOL) isKindOfClass: classObj 判断是否是这个类或者这个类的子类的实例/ 判断是否是这个类 ...
- Linux 日常运维
查看用户信息:w 查看系统负载:uptime 查看系统资源使用情况:vmstat 查看进程动态:top 查看网卡流量:sar 查看网卡流量:nload 查看磁盘读写:iostat 查看磁盘读写:iot ...
- [Windows] Windows 8.x 取消触摸板切换界面
在鼠标中选中UltraNav,找到Application Gestures - Edge Swipes,取消Enable Edge Swipes.
- 学习下新塘M0芯片的下载方法
编程方式多种多样,解释这几种方式的原理,方便做后续的回答: 一.脱机 脱机的意思就是脱离PC机,有很多芯片必须连接PC才能烧录,比如某些FPGA芯片.MCU芯片.NAND Flash芯片等.脱机和在线 ...
- Android井字游戏(一)首页制作
创建一个新程序: 应用名: Tic Tac Toe 公司域名: example.org 尺寸: Phone and Tablet 最低SDK: API16: Android 4.1 添加活动: Emp ...
- shell 数值计算
shell中的赋值和操作默认都是字符串处理,在此记下shell中进行数学运算的几个特殊方法,以后用到的时候可以来看,呵呵. 1.错误方法举例 a) var=1+1 echo $var ...
- dpkg安装deb缺少依赖包的解决方法
[先贴出解决方案(基于Ubuntu)]: 使用dpkg -i *.deb 的时候出现依赖没有安装 使用apt-get -f -y install 解决依赖问题后再执行dpkg安装deb包 === ...
- ftp主动与被动模式区别
FTP是仅基于TCP的服务,不支持UDP.与众不同的是FTP使用2个端口,一个数据端口和一个命令端口(也可叫做控制端口).通常来说这两个端口是21(命令端口)和20(数据端口).但FTP工作方式的不同 ...
- 跟bWAPP学WEB安全(PHP代码)--邮件头和LDAP注入
背景 由于时间限制和这俩漏洞也不是特别常用,在这里就不搭建环境了,我们从注入原来和代码审计的角度来看看. 邮件头注入 注入原理: 这个地方首先要说一下邮件的结构,分为信封(MAIL FROM.RCPT ...
- Laya 图集动画
参考: 图集动画运用 一.准备素材 从爱给网找到几个素材 二.使用Laya的图集工具 菜单栏选择工具->图集打包工具,然后选择序列图所在的文件夹 生成了个.rec...说好的.atlas呢... ...