150
edits
Changes
→Code for Intel Inspector
[[File:FalsePositive.png]]
== False Positive ==
<syntaxhighlight lang="cpp" line='line'>
#include <iostream>
using namespace std;
const int maxSize = 10;
int main()
{
// declaring an array of pointers
int** mypointer = new int* [10];
// populating the array with pointers
cout << "\n Populating Array With Pointers \n" << endl;
for (int i = 0; i < maxSize; i++)
{
mypointer[i] = new int;
*mypointer[i] = i;
cout << *mypointer[i] << endl;
}
cout << "\n -----------------------------------------------" << endl;
// Switching every even numbered pointer to be pointing towards the next odd numbered pointer
cout << "\n deleting pointers \n" << endl;
int* deletor;
for (int i = 0; i < maxSize; i++)
{
deletor = mypointer[i];
cout << "Deleting [" << *deletor << "]" << endl;
delete deletor;
}
cout << "\n -----------------------------------------------" << endl;
//Printing the results;
cout << "\n Making everything a nullptr \n" << endl;
for (int i = 0; i < maxSize; i++)
mypointer[i] = nullptr;
cout << "\n Checking nullptr's" << endl;
for (int i = 0; i < maxSize; i++)
{
if (mypointer[i] == nullptr)
cout << "pointer [" << i << "] is a nullptr" << endl;
}
delete[] mypointer;
cout << "\n **There should be no memory leak**" << endl;
return 0;
}
</syntaxhighlight>
= How to use Intel Parallel Studio Inspector =