Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Memory Leakage (http://www.go4expert.com/forums/memory-leakage-t26267/)

manaila 12Jul2011 18:58

Memory Leakage
 
Hi,
I am developing an embedded system using C. I have a limited memory, so I sometimes run into a problem whereby my system becomes totally trashed due to memory leakage.
So I am asking for suggestions and recommendations about the sources of memory leakage and how I can avoid them.

seangtz 13Jul2011 09:28

Re: Memory Leakage
 
I hope this article will help you
http://mariusbancila.ro/blog/2010/07...-memory-leaks/

xpi0t0s 13Jul2011 16:26

Re: Memory Leakage
 
Make sure that *EVERY* memory allocation is matched by a memory free, WITHOUT EXCEPTION.
Then it won't leak.

manaila 6Oct2011 12:18

Re: Memory Leakage
 
I wish want to further the discussion. When we have something like this:
Code:

char myFunc(char* a, char* b)
{
    ...
}

then, do we still have to make memory deallocation?

xpi0t0s 6Oct2011 18:48

Re: Memory Leakage
 
There is one situation where you need to free memory, which is where you have allocated it. If you have allocated it then you MUST deallocate it (when you've finished with it). If you have not allocated it then you MUST NOT deallocate it. That's all there is to it.

It's good practice to allocate and deallocate memory within the same function wherever possible, e.g.:
Code:

void doSomething()
{
  struct summat *newThing = malloc(sizeof(struct summat));
  do_something_else(newThing);
  free(newThing);
}

If this isn't possible then it's a good idea to hand off memory management responsibility to a memory management class or family of functions, which would encapsulate the handling of that memory and make it all fairly easy to find, compared with splattering malloc calls all over the place.

StarDrago 18Jan2012 01:51

Re: Memory Leakage
 
u can use deleaker or similar debugger for search gdi and memory leaks.


All times are GMT +5.5. The time now is 20:15.