const字符串内存泄漏? [英] const string memory leaks?

查看:138
本文介绍了const字符串内存泄漏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在完成一个项目,现在我正在检查内存泄漏.老实说,我过去并没有做很多事情,但是这个项目比我以前做的任何事情都更大,更重要.

无论如何,我的问题是我声明了以下常量列表:

So I''m finishing just finishing up a project, and right now I''m checking for memory leaks. To be honest, I haven''t done a whole lot of this in the past, but this project is quite a bit larger and more important than anything I''ve done previously.

Anyway, my problem is that I have the following list of constants declared:

const string RES_START = "// INSERT RES TEST";
const string IR_START = "// INSERT IR TEST";
const string DI_START = "// INSERT DIELECTRIC TEST";
const string PART_PRETEST = "// INSERT PART PRETEST";
const string CABLE_PROMPT = "// INSERT CABLE PROMPT";
const string LUA_MKDIR = "// INSERT LUA MKDIR";
const string LUA_SERIAL = "// INSERT LUA SERIAL";
const string TESTS = "// INSERT TESTS";
const string PRINT_TESTS = "// INSERT TEST PRINT";
const string DATE_TAG = "// DATE";
const string AUTHOR = "// AUTHOR";



当我在程序退出之前转储内存泄漏时,这些都显示为泄漏!我也有一些int常量,它们不会以内存泄漏的形式出现.我应该做些不同的事情吗?我应该不只是为字符串制作常量吗?

预先感谢,
Pat



When I dump my memory leaks before my program exits, these all show up as leaks! I have some int constants as well that are NOT appearing as memory leaks. Is there something I should be doing different? Should I just not be making constants for strings?

Thanks in advance,
Pat

推荐答案

没关系,它只会在程序结束时被破坏/释放.
Thats fine, it will be only destructed/released when your program ends.


string显示内存int泄漏,因为string内部在堆上动态分配内存.
并猜测这些变量是全局变量,如果您在程序结束之前转储内存,则会显示泄漏,因为这些字符串仍然有效.
The string shows memory leak over an int because a string internally allocates memory dynamically on the heap.
And guessing that these variables are global, they will show a leak if you dump memory before the program ends because these strings are still alive.


这篇关于const字符串内存泄漏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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