Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more: , +
Hi all,
After spending one whole day on google search about "mfc exe memory consumes lots of space of RAM".Nothing useful found.
So as usual need expert like all of you guys,


Problem Start when i run my window based application on my PC.It make my PC incredibly slow.Because out of my 2 GB RAM my exe cosumes 500MB RAM.
My project architecture,
My window based project totally depend on MFC dynamic DLL.
in which exe loads DLL as per requirement.

So i need a solution or at least hint to reduce memory consumption of my exeon RAM.

Note :-
On every loading of DLL my exe increase space on RAM.

thanks
Posted
Updated 28-Aug-12 20:24pm
v2
Comments
Mehdi Gholam 29-Aug-12 2:53am    
You could have a memory leak, use a memory profiler on you exe.
Coder Block 29-Aug-12 3:59am    
what is memory profiler please need more information
Joan M 29-Aug-12 3:15am    
Each time you finish with a resource you should free it, check for memory leaks.
Coder Block 29-Aug-12 3:58am    
thanks for reply,
Can you just tell me what is memory leack and when it occure and how to find it and resolve it???
Joan M 29-Aug-12 4:07am    
A memory leak is when you allocate some memory to store anything there and when you've finished using it you don't free it again. Then, when this happens, that memory will get marked as used and until you close your app it won't be freed.
It is really important to follow the rules allocating and freeing memory.
In order to find that... well I can promise you that this is like a nightmare, as Mehdi Golam suggested, go for a code profiler.
The most common places to have memory leaks is using pointers, strings, lists... if you load a dll, don't free the resources it is using and then you load it again...
I'm sure you get the picture.
I'm sorry, but you will need to find it.
If you can't find a better way to do it, put the suspect code inside a loop and run it to see if the memory is getting wasted or not...

 
Share this answer
 
Comments
Coder Block 30-Aug-12 0:15am    
thank,
all are sharewares!!need as usual freeware!!!:D
Visual Studio has a built in memory profiler....

Place the following in each of your .cpp files after the include statements.

C++
#ifdef _DEBUG
#define new DEBUG_NEW
#endif



Then run your application in the debugger in debug mode.
Close your application.

You'll see any memory leaks from these files, documented in the output window.
If you have a lot of leaks, it may take a while to compile the report.
 
Share this answer
 
v3
Comments
Coder Block 30-Aug-12 0:13am    
Thanks a lot but,
lets my program have memory leak what is a solution!!!
is there some think like garbage collection in mfc?
if yes then how it apply and how it define in mfc programing
JackDingler 30-Aug-12 8:38am    
I gave you a solution that will tell you exactly which line of code is allocating the memory. We can't guess what your source code looks like, and tell you where the leak is, in code we've never seen.

MFC is pretty solid. It doesn't have any leaks like you describe. This leak comes from something you wrote.





Coder Block 30-Aug-12 8:49am    
agree !!
But even mfc is pretty solide..
If my self or one of my cullies done mistak like
CAbcclass* obj;
obj = new CAbcclass;
And "obj" not used in whole project .
Then is there memory leak . If yes then what is
solution?
And if solution is garbage collection then how it apply in
mfc.
Sorry to ask but i am so confused ....
JackDingler 30-Aug-12 9:43am    
MFC is simply a class library to help you interface with the OS. It's not MFC that is giving you these problems. What you're having trouble with is the C++ language and how it should be used. You would've had the same problems in Linux with C++.

If you call 'new', then somewhere you must call 'delete'.

If you call malloc() or calloc() or strdup() then you must call free().

When you're done with memory you allocate, you must release it.

That's it in a nutshell.
Coder Block 3-Sep-12 23:55pm    
thanks delete is more useful for memory leak.
thank you so much.

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