本文介绍了动态的分配方式时,程序使用Ctrl-C中断释放的空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于以下code:

#include <stdio.h>

int main()
{
    int *p;
    p = (int *)malloc(10 * sizeof(int));

    while(1);
    return 0;
}

在上面的code编译并运行,被中断,而在由pressing 按Ctrl + C ,怎么会是内存分配给点执行中解脱出来?什么是这里的操作系统的作用?又是怎样的,在案件C ++不同的是,使用运营商做了什么?

When the above code is compiled and run, and is interrupted while in execution by pressing , how is the memory allocated to p freed? What is the role of the Operating System here? And how is it different from that in case Of C++, done using the new operator?

推荐答案

当一个进程终止时,操作系统会回收进程使用的所有内存。

When a process terminates, the operating system reclaims all the memory that the process was using.

人们之所以小题大作了内存泄漏,即使操作系统收回你的应用程序中使用被终止时内存通常不平凡的应用将很长一段时间运行在慢慢吞噬所有的记忆系统。这是一个问题较少的很短的生命周期计划。 (但你永远无法知道,当一个班轮将成为一个庞大的计划,所以在小程序没有任何内存泄漏偶数。)

The reason why people make a big deal out of memory leaks even when the OS reclaims the memory your app was using when it terminates is that usually non-trivial applications will run for a long time slowly gobbling up all the memory on the system. It's less of a problem for very short-lifetime programs. (But you can never tell when a one-liner will become a huge program, so don't have any memory leaks even in small programs.)

这篇关于动态的分配方式时,程序使用Ctrl-C中断释放的空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 14:36