Home  Easy-Code   Forum    Updater 

Not signed in (Sign In)
    • CommentAuthorbrother2
    • CommentTimeNov 22nd 2010
    Applications developed in C/ C++ do have the ability to allocate memory dynamically and deallocate after the use. There are many instance because of lack of knowledge on coding rules or by overlook or design flaws programmers might miss to deallocate the memory that is allocated dynamically and this leads to unnecessary comsumption of memory by the computer program causing memory leak.

    A simple example of memory leak,

    int returnlength()
    char *ptr=(char *) malloc(1024); /* memory is allocated*/
    return strlen(ptr) ;

    Here in the above example programmer has allocated the memory of 1024 charecter bytes and missed to dealloacte the memory which caused unnecessary comsumption leading the memory leak in the application.
    • CommentAuthorbrother1
    • CommentTimeNov 22nd 2010
    I understood what is a memory leak in C/ C++ applications, but how do we identify such memory leaks in applicaitons with millions of lines of sources code?
    • CommentAuthorbrother2
    • CommentTimeNov 22nd 2010
    There are runtime tools like Valgrind, PurifyPlus and also, we can use DTrace scripting in sun machines to determine these memory leaks. All these tools are runtime tools and the leaks are determined to a particular flow of code that is excuted with the tool. So, the performance tester need to ensure that right flow covering all the functions and possible control flows are used to determine all possible leaks.

    Out of all these tools PurifyPlus - Purify from IBM, is mostly is used and available on all platforms. The workflow to determine leaks is as follows,
    Step1: Instrumented the sources
    Step2: Indentifying the best possible transaction scenarios
    Step3: Executing the identified scenarios with the instrumented code
    Step4: Verifying the purify report for the memory leaks
    Step5: Go to step1 till NO memory leaks are available in the application

    1. If the code is compiled with -g option then only the report shall contain the source line number where exactly the memory leak is reported.
    2. The report will be the stack trace of functions from where the leak is generated the tester/ coder has to go through all the functions from top to bottom and determine the right function where to deallocate the memory.
    • CommentAuthorbrother1
    • CommentTimeNov 22nd 2010
    Good to know this information. How do I prove or test the existence of memory leaks in the application?
    • CommentAuthorbrother2
    • CommentTimeNov 22nd 2010
    Endurance runs are part of the performance testing of the application, these runs are executed to test existence of memory leaks in the application.

    Endurance run is a peformance run executed on the application for a longer duration for 12-24 hrs or more, continuously without any interruptions to verify if the memory comsumption on the application is constant or not. If the memory consumption is constant then we consider that the application is free from memory leaks else if the memory is increasing periodically then we conclude that the application has memory leaks.