This is a discussion on Memory leaks in C program within the C and C++ forums, part of the Programming Talk category; In my C program I use both "new" and "malloc" keywords, I want to know about ...
|
|||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Memory leaks in C program
In my C program I use both "new" and "malloc" keywords, I want to know about memory leaks, What are the consideration when I use "new" and "malloc" keywords. Should I take any extra care to fix memory leaks? Please help me learn
Charith |
|
||||
|
There are various scenarios in which memory leaks can occur and taken care of in C program. I have specified some of them below:
Memory leaks can occur during a realloc. That is suppose if a programmer uses the same pointer as the pointer used in original memory allocation for the realloc pointer and if suppose the realloc fails then the pointer would be set to NULL which would make the previously allocated memory also having no pointer for it. This is one of the situations of memory leak. To handle this situation what one can do is use a temporary pointer for realloc so that even if realloc fails, it would not cause big hazard as the pointer on the original memory space is kept as such. Since any memory space that loses its pointer or which is not free'd is called as memory leak it is always good to use free and the syntax of using this is void free(void *p); In the above free is a keyword which takes the pointer for freeing as argument.
__________________
Regards, Admin http://www.exforsys.com http://www.geekinterview.com http://www.itquestionbank.com http://www.myitblog.com |
|
|||
|
nice post, clears up some confusion
|
![]() |
| Thread Tools | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| comp.lang.c Answers (Abridged) to Frequently Asked Questions (FAQ) | Steve Summit | Tech FAQ | 0 | 06-15-2004 07:00 AM |
| comp.lang.c Answers (Abridged) to Frequently Asked Questions (FAQ) | Steve Summit | Tech FAQ | 0 | 06-01-2004 07:01 AM |
| comp.lang.c Answers to Frequently Asked Questions (FAQ List) | Steve Summit | Tech FAQ | 0 | 06-01-2004 07:00 AM |
| comp.lang.c Answers (Abridged) to Frequently Asked Questions (FAQ) | Steve Summit | Tech FAQ | 0 | 05-15-2004 07:00 AM |
| Apple II Csa2 FAQs: Telecom Hardware & Transfers, Part 20/25 | rubywand@swbell.net | Tech FAQ | 0 | 04-04-2004 08:29 AM |