Click here to Skip to main content
11,576,354 members (60,677 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VC6 VC7 VC7.1 VC8.0 Visual-Studio , +
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 28-Aug-12 20:22pm
Edited 28-Aug-12 20:24pm
v2
Comments
Mehdi Gholam at 29-Aug-12 2:53am
   
You could have a memory leak, use a memory profiler on you exe.
Coder Block at 29-Aug-12 3:59am
   
what is memory profiler please need more information
Joan Murt at 29-Aug-12 3:15am
   
Each time you finish with a resource you should free it, check for memory leaks.
Coder Block at 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 Murt at 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...
Coder Block at 29-Aug-12 4:28am
   
sorry to ask but need straight way!!
Joan Murt at 29-Aug-12 4:33am
   
Sorry to say, but without code and without a minimum amount of knowledge of a memory leak... See the answer of Mehdi Golam.
How do you load the DLLs?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Comments
Coder Block at 30-Aug-12 0:15am
   
thank,
all are sharewares!!need as usual freeware!!!:D
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Visual Studio has a built in memory profiler....

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

#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.
  Permalink  
v3
Comments
Coder Block at 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 at 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 at 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 at 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 at 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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 271
1 F-ES Sitecore 140
2 Abhinav S 125
3 Lucifier Rocks 105
4 OriginalGriff 80
0 OriginalGriff 705
1 Sergey Alexandrovich Kryukov 626
2 Abhinav S 483
3 F-ES Sitecore 410
4 Suvendu Shekhar Giri 365


Advertise | Privacy | Mobile
Web04 | 2.8.150603.1 | Last Updated 29 Aug 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100