本文介绍了我应该自由分配在异常终止内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序(文本模式的网页浏览器)是动态分配内存。

My program (a text-mode web browser) is dynamically allocating memory.

我在运行时做的,当然不需要自由块。而我做的一切自由正常终止前 - 让内存泄漏跳棋不会给我误报(和灵活应成为有史以来需要重构各大)

I do free unneeded blocks during runtime, of course. And I do free everything before normal termination - so that memory leak checkers won't give me false positives (and to be flexible should major refactorings ever become needed).

现在,我做什么的的做的是异常终止之前释放内存。 (目前,我的程序终止的信号,未能mallocs / reallocs后)。

Now, what I do not do is freeing memory before abnormal termination. (Currently, my program terminates on signals and after failed mallocs/reallocs.)

我的问题是:你认为这种不良作风?我应该释放的异常终止?

My question is: Do you consider this bad style? Should I free on abnormal termination?

推荐答案

没有。我认为这是完全可以接受的只是扔了你的手,让操作系统回收内存的程序终止后。我想,如果这确实是一个不正常的情况和意图是让程序终止,那么乖巧方案应该简单地清理任何磁盘资源/锁,并退出尽可能快的。

No. I think it's perfectly acceptable to simply throw up your hands and let the OS reclaim the memory after the program terminates. I think if this is truly an abnormal situation and the intention is to have the program terminate, then a well-behaved program should simply clean up any disk resources/locks, and exit as quickly as possible.

这篇关于我应该自由分配在异常终止内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 10:35