Using Memory Profiling to Remove Memory Leaks

By using the call stacks displayed in the Memory Profile viewer, you will deduce the corrections that need to be made to eliminate memory errors.

To locate and fix memory errors:

  1. Select the Memory Profile tab.

  2. Select the ABWL error node in the Report Window on the left hand side of the screen.

Have a look at the call stack for the Late Detect Array Bounds Write error. Three C++ methods are listed.

  1. Select the last function first, the one that occurs inside main()

Within the main() procedure a UmtsServer object is instantiated. Nothing looks out of sorts here, so return to the call stack.

  1. Close the source file for the main() procedure, and then click the second function from the bottom in the call stack referenced by the ABWL error - the UmtsServer constructor.

The next function in the stack is the UmtsServer constructor. The line in the constructor that is flagged, the creation of a NetworkNodes object, is a call to the List constructor. Continue to follow the sequence of events.

  1. Close the source file for the UmtsServer constructor, and then click the top function in the call stack referenced by the ABWL error - the List constructor.

The highlighted line is a call to malloc. A quick look at this function shows that a return to the UmtsServer constructor is fairly quick, and nothing seems unusual. You should continue to track the string of events as they happened to see if the ABWL error shows itself. Return to the UmtsServer constructor.

  1. Close the source file for the List constructor, and then click the second function from the bottom in the call stack referenced by the ABWL error - the UmtsServer constructor.

What happens next? The NetworkNodes object was assigned 3 List objects in an array. Immediately following the call to the List constructor, 4 elements are assigned to this array. Not good. The NetworkNodes object should be an array of 4 List objects, not 3.

  1. In the source code, change the line

networkNodes = new List(3);

to

networkNodes = new List(4);

  1. From the File menu, select Save. The revised file UmtsServer.cpp is saved.

This should fix the ABWL error. Before redoing you manual test to verify if the memory error was fixed, move on to the Performance Profile viewer and see if you can streamline the performance of the UMTS base station code.

As for the other memory warnings - that's for you to figure out!