
- Forum
- Programming Talk
- C and C++
- Memory leaks in C program
Memory leaks in C program
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 memory leaks, What are ...
-
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
-
12-14-2006, 05:37 AM #2
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.
-
Hello Admin
Thanks a lot for posting answer to my question
I am very happy
Thanks again
Charith
-
It was really a very useful post on Memory leaks. Thanks to the admin for such a wonderful posts.
-
nice post, clears up some confusion
-
Sponsored Ads

Reply With Quote





