|
-
February 19th, 2007, 11:31 AM
#1
Free Memory
Hi, does anybady know if there's any function or way to free all the memory used in c++ till that moment? i'm having problems with a program which ends wrong after using during a period of time (not short but not long) and i've revised too many times the code and i think that i'm freeing well, but the program ends at different places without a reasonable explanation, and it smells me that it could be a memory problem, out of memory. Thanks
Last edited by minagu; February 19th, 2007 at 11:40 AM.
-
February 19th, 2007, 11:52 AM
#2
Re: Free Memory
it theoretically may be everything , but probably you have some bug(s) in your code
if you don't release some memory, IDE will yell in Debug mode when you exit the application. there are also tools like BoundaryChecker which perform some validations to catch out-of-boundary writes.
you also can use any pos-mortem debuggers like WinDbg even with Release build (and Generate Debug Information checkbox checked), so you can see the crash in 'live' mode and get the line where it crashes
Cheers,
Alex
 Please rate this post if you find it helpful 
-
February 19th, 2007, 12:24 PM
#3
Re: Free Memory
What happens if you let it crash in the debugger? Windows should let you know if you're running low on memory before your program crashes.
-
February 19th, 2007, 12:56 PM
#4
Re: Free Memory
If i run the program with borland c++ there's no crash(or at least it spends too much time till crashing), is only when i run the ".exe". And as after the exit of the program, i know that all the memory used is freed i would want to know if there's any way or function with i could free the memory used and start again without exiting the program.
-
February 19th, 2007, 01:01 PM
#5
Re: Free Memory
 Originally Posted by minagu
[...] and it smells me that it could be a memory problem, out of memory.
To be a little bit more sure and not just smelling the cause, open the Task Manager and look at memory usage of your process.
-
February 19th, 2007, 01:16 PM
#6
Re: Free Memory
i've looked the task manager while running the process, and the use of memory grows up step by step.
-
February 19th, 2007, 01:33 PM
#7
Re: Free Memory
And can you confirm Windows is running out of memory? Some languages feature garbage collection, but C++ isn't one of them. Any function that unconditionally freed all memory being used would cause a crash anyway.
This is a Microsoft forum, so I don't know what tools are available in Boreland. Visual C++ debugger will give you some idea of what objects have been created but not deleted when the program ends. Maybe Boreland has something similar. If possible, trying commenting out various parts of your code to try to find where the leak is coming from. That'll make it easier to fix.
-
February 20th, 2007, 06:38 AM
#8
Re: Free Memory
But i don't think that a function which could free the memory used could cause a crash, because when you close de program, there are functions used to free all the memory and there's no crash, so i'm looking for a function which could free the memory used.
-
February 20th, 2007, 07:19 AM
#9
Re: Free Memory
in your program First thing instead of pointer use STL classes or still if you want to go with pointer use smart pointer. so it will minimize the risk of memory leak etc.and second thing reason of your problem can be some short of infinite loop. have alook back in your code.
Thanx
-
February 20th, 2007, 07:49 AM
#10
Re: Free Memory
Minagu, when closing an application the memory allocated is freed _after_ execution is finished. I.e. it's impossible to get an application crash. If you really find a function that frees all allocated memory while the application is still running, there will most definitely be a crash.
The solution is as always the one that involves a lot of pain... find the bugs... 
I'm sorry but you will not find much debugging help within the Borland IDE. Is your code using a lot of Borland stuff? If not, try porting your code to Microsoft Express which give you a lot better support in tracking down the (pointer/allocation) bugs.
Regards
/SMA
-
February 20th, 2007, 08:45 AM
#11
Re: Free Memory
Borland or not Borland, but WinDbg will always show you where the crash is, so you can use it to solve this problem. A nice tutorial is available here
Cheers,
Alex
 Please rate this post if you find it helpful 
-
February 22nd, 2007, 07:59 AM
#12
Re: Free Memory
It's a clear out of memory, because in the task manager, at the begining when i execute the ".exe" the aplication uses near of 100-130 Mb of Ram, and after one hour and half, or two, the use increases to 570Mb, and in a computer with 512MB or 1GB of RAM that will crash. The increase is produced when i generate .xls files using AutWrap functions, it consumes RAM memory, without freeing when it ends.
The strange thing is that if i execute it from borland there's no crash or at least i've had no problem, but continues the increase.
-
February 22nd, 2007, 09:26 AM
#13
Re: Free Memory
There's really nothing any of us can do for you except tell you to run it in the debugger and see where it crashes. You could try a leak detection tool such as BoundsChecker too I suppose. Maybe comment out sections of your code to try to find out which part is causing the leak.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|