Click here to Skip to main content
16,018,496 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
C#
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";


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
Posted
Comments
Albert Holguin 27-Jul-11 21:31pm    
Even though as stated below, it shouldn't be a problem, I could see how this would bother you (seeing a memory leak reported)... have you tried using const char[] instead to see if you get the same leak report? Its probably because string is actually based on a template class rather than being a fundamental data type.

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.
 
Share this answer
 
Thats fine, it will be only destructed/released when your program ends.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 27-Jul-11 17:45pm    
You are right, my 5. It's all reduced to the problem: what's a memory leak? It's something related to circular behavior; when you come the same point where the memory usage is supposed to be the same but it is not...
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900