Sunday 7 October 2012

Detect Memory Leak in C++

Memory leak description: Memory is allocated but not released causing an application to consume memory reducing the available memory for other applications and eventually causing the system to page virtual memory to the hard drive slowing the application or crashing the application when than the computer memory resource limits are reached. The system may stop working as these limits are approached
http://www.yolinux.com/TUTORIALS/C%2B%2BMemoryCorruptionAndMemoryLeaks.html

Memory leak in Java

http://info.appdynamics.com/rs/appdynamics/images/Top_10_Java_Performance_Problems_eBook.pdf
http://stackoverflow.com/questions/6470651/creating-a-memory-leak-with-java

http://www.agiledeveloper.com/articles/MemoryLeak092002.pdf
http://www.openlogic.com/wazi/bid/188158/How-to-Fix-Memory-Leaks-in-Java
http://www.cs.utexas.edu/users/speedway/DaCapo/papers/leak-tr-06-07.pdf


Avoiding memory leaks in POSIX thread programming

Listing 1. Creating a memory leak

#include<stdio.h>
#include<pthread.h>
void run() {
   pthread_exit(0);
}

int main () {
   pthread_t thread;
   int rc;
   long count = 0;
   while(1) {
      if(rc = pthread_create(&thread, 0, run, 0) ) {
         printf("ERROR, rc is %d, so far %ld threads created\n", rc, count);
         perror("Fail:");
         return -1;
      }
      count++;
   }
   return 0;
}

Preventing leaks

Joinable threads should be joined during programming. If you are creating joinable threads in your program, don't forget to callpthread_join(pthread_t, void**) to recycle the private storage allocated to the thread. Otherwise, you'll introduce serious memory leaks.

http://hea-www.harvard.edu/~fine/Tech/addrinuse.html

How to Avoid this Error when Closing TCP Connections

No comments:

Post a Comment