This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

memory leaks

I want to know about memory leaks
1)what are memory leaks
2)how you handle memory leaks in C programming using keil compiler.
3)please can anybody provide me the complete documentation about handling memory leaks using keil compiler?
4)what are different possible cases a memory leaks can occur in a C programming and how to overcome them.
5)what are the necessary steps to be taken when programming to avoid such bugs(memory leaks)

  • I want to know about memory leaks

    Is this homework ?

    1)what are memory leaks

    Dynamic allocation of memory without subsequent deallocation once the block of memory is not used anymore. That'll slowly eat up your memory as your operating system runs out of free space.

    2)how you handle memory leaks in C programming using keil compiler.

    You don't "handle" memory leaks in C. You make sure there aren't any, period. Other languages might be different here - JAVA has built-in garbage collection, where the system itself takes care of deallocating unused memory blocks. There are some attempts of piggybackign a garbage collector onto C, but you should seriously rethink your choice of programming language if you consider doing something like this.

    However, if you use dynamic memory allocation on the '51 architecture, you should seriously rethink your choice of MCU. The '51 memory architecture is notoriously bad at handling dynamically allocated memory - and since the amount of memory available is known in the design phase (you should know which chip you are programming for), memory can easily be statically allocated, saving you all the headaches of dynamic memory allocation (for example error handling - what do you do when your malloc() fails ?)

    3)please can anybody provide me the complete documentation about handling memory leaks using keil compiler?

    See #2. In C, you make sure there are no memory leaks. Memory leaks are bugs. You don't handle bugs, you remove them from your program.

    4)what are different possible cases a memory leaks can occur in a C programming and how to overcome them.

    That is a weird question.

    5)what are the necessary steps to be taken when programming to avoid such bugs(memory leaks)

    You must make sure that every block of dynamically allocated memory is eventually deallocated when it is not used anymore. That's all there is to avoiding memory leaks.

    In C++ you would say "For every new, you must delete.".

  • You do know that most universities and other schools have special software that scans forums for people who try to "offload" their school assignments?

    Getting caught is not something to look forward to! In best cases (for you), you will only be forced to stay away from the school for a couple of weeks. But, you may be kicked out too...

    Remember that Google is very efficient, and your questions will match, if your teacher does a scan of his questions!

  • Maybe not necessary, but certainly sufficient: just don't use dynamic memory allocation.
    Especially on an 8051!

  • The problem with garbage collection is that it solves only one small fraction of resource acquisition and release problems. The programmers that can't eliminate memory leaks from their code without a GC are also the ones that deadlock the system because they can't release semaphores or halt the system because they forget to unmask interrupts.

    GC should be a component of a system that you add or not, as suits the problem.