|
hrm.. nevermind i don't think thats it.. i think i should be able to track it down, thanks for the advice, and thanks for letting me know about deleting brushes too!
thanks!
-dz
|
|
|
|
|
Try this console code, it demonstrates C Runtime Library on memory leak detection.
#include <iostreamᡊe9ac73-238b-46be-991d-0f050c37248d#include <crtdbg.hᡊe9ac73-238b-46be-991d-0f050c37248d
using namespace std;
void main()
{
_CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF | _CRTDBG_ALLOC_MEM_DF);
_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
_CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDOUT);
int* p = new int;
*p = 4;
p = 0;
delete p;
}
Maxwell Chen
No code is good code.
|
|
|
|
|
and if you defines #define _CRTDBG_MAP_ALLOC before any includes, you also get the line where you allocated the (not free'd) memory...
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
But when I applied those functions
_CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF | _CRTDBG_ALLOC_MEM_DF);
_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
_CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDOUT); in MFC app projects, set the debug argument to redirect the report to some txt file like MemLkRpt.txt , nothing's reported in that file. How should I do, like: when should these _CrtSet???( ) functions be called, in the ctor of theApp, or some other where? Any additional steps must be taken? ... etc.
And by the way, I can not delete the generated MemLkRpt.txt file!
Thanks
Maxwell Chen
No code is good code.
|
|
|
|
|
Serialization can also give memory leaks. If your not 100% sure about whats going on.
If you have an object that can be created dynamically from serialization you could do this:
CMyObject *pObject = new CMyObject ;
ar >> pObject ;
... stuff
delete pObject ;
The problem here is that your new ed object is lost as the serialization code allocates another object itself dynamically.
Roger Allen
Sonork 100.10016
If I had a quote, it would be a very good one.
|
|
|
|
|
I want to set up an #if condition based on a environment variable,
anyone know if it's possible to set up such a thing?
(I'm using VC6)
/Magnus
|
|
|
|
|
I don't believe so. Retrieving an environment variable would entail running code. The #if is a preprocessor directive that is resolved at compile-time, before your code runs.
Cheers,
Tom Archer
Author, Inside C#
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
|
|
|
|
|
Yes, that i am aware of, i tought maybe someone knew of some wierd
#pragma directive or similar that did the trick.
Looks like i have to do some .bat file that runs nmake.
(Back to the 80's )
/Magnus
|
|
|
|
|
Either that or maybe write a preprocessor-like app whose sole job is to inspect an environment variable and update a #define in a global header file. The advantage being that you would still be able to use the normal VS/VC make. I don't know how to inject a processor into the mix, but I'm sure that it can be done.
Cheers,
Tom Archer
Author, Inside C#
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
|
|
|
|
|
That sonud like a nicer soultion.
I'll will try and fine some pre-compile place where i can hook the thingy in.
/Magnus
|
|
|
|
|
Actually, thinking more about it now. You would think that writing an add-in that does what I'm proposing here (updating a global file's #define) and then using the VS object model to kick off the build. THat would give you the best of both worlds (an add-in vs a preproccesor) and would be a solution that is already documented (the writing of add-ins). I would think that that would be easier than finding dox on preprocessing. What do you think?
Cheers,
Tom Archer
Author, Inside C#
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
|
|
|
|
|
I agree that that sounds like the most elegant solution.
However for now im just looking for the fastest way to get it
working and that way would require me to dig in to DevStudio add-in writing.
I'll probably will do it the 'proper' way when i got some more time over.
/Magnus
|
|
|
|
|
I hear you, mate. Unfortunately deadlines often get in the way of the cool stuff we want to write
Cheers,
Tom Archer
Author, Inside C#
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
|
|
|
|
|
If you are using DevStudio I can see two possible ways:
1) VB Macro. They are simple to write but I don't know if VB has the methods needed to read the environment. There is an object to control the build, the BuildProject object.
2) Developer Studio Add-In. This is a compiled .dll so I you could do anything here that C/C++ allows you to do. Problem is they are more complex to write then a macro. But there are some nice examples on CodeProject.
Good luck,
David
|
|
|
|
|
That might be a way to do it.
If VB dont have the requried methods thay can easily be added trough a COM object
I'll ponder on the options for a while.
/Magnus
|
|
|
|
|
(smack forehead) DOH! Much better than my recommended way. An add-in or macro would be the best way to do it. Nice suggestion!
Cheers,
Tom Archer
Author, Inside C#
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
|
|
|
|
|
Do you mean :
int num = 3;
if(num == 5)
#define _A
#undef _B
{ }
else
#define _B
#undef _A
{ }
#if defined(_A)
cout << "_A defined.\n";
#endif
#if defined(_B)
cout << "_B defined.\n";
#endif
The result is :
_B defined.
Maxwell Chen
No code is good code.
|
|
|
|
|
Has anyone tried using this function? It wants seconds for the new timeout value but everything I throw at it fails. Or I should say returns "0", which is supposed to be failed. I even tried the default value of 120 without luck.
It does seem to do something to the timeout - makes it about 5 minutes regardeless of what value I set.
I'm testing on W2K Workstation Professional SP2.
Thanks,
David
|
|
|
|
|
Can someone help me with the code necessary to update the HKEY LOCAL MACHINE | SOFTWARE | Microsoft | Windows | CurrentVersion | RunOnce registry key?
Kyle
|
|
|
|
|
There are seveal registry classes on CodeProject. Do they not do what you need?
Cheers,
Tom Archer
Author, Inside C#
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
|
|
|
|
|
I have been exploring this for hours. The one by PJ Naughter seems the most promising but I haven't been able to figure out how to get it to update any of the keys except the one he wrote for his company. What he wrote looks great. I'm just struggling because I can't get it to work for me. The problem is me and that is why I asked for help.
Kyle
|
|
|
|
|
I have a much simpler CRegistry class that has always worked for me. If you want, I'll send it to you.
Cheers,
Tom Archer
Author, Inside C#
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
|
|
|
|
|
Tom, I would be very grateful. Thank you for the generous offer. I will be anxiously waiting. Please send to Kyle@TrustLine.com.
Thanks,
Kyle
|
|
|
|
|
It's on the way. I think you'll find it very easy to work with. Lemme know if you have any questions.
Cheers,
Tom Archer
Author, Inside C#
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
|
|
|
|
|
Thank you Tom! I'll let you know how it goes.
Kyle
|
|
|
|