当超出范围时,将释放所有自动存储变量,并且您必须明确动态分配的变量:
void foo()
{
int x;
int* y = new int;
//You get a memory leak with each call to foo without the following line
delete y;
} //x is freed here
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
128 次 |
| 最近记录: |