Analyzers
Talk to fellow users of Intel Analyzer tools (Intel VTune™ Profiler, Intel Advisor)

How to understand 'Mismatched allocation/deallocation'?

Zhanghong_T_
Novice
666 Views

Dear all,

I have the following code:

...

  idx2faclist = new int[points->items + 1];


...

  delete [] idx2faclist;


...

The Intel Inspector gives me 'Mismatched allocation/deallocation' error message for the line

  idx2faclist = new int[points->items + 1];

and

  delete [] idx2faclist;

 

How to understand this error message? How to modify the code to remove this error message?

 

Thanks,

Zhanghong Tang

0 Kudos
5 Replies
Bernard
Valued Contributor I
666 Views

Probably there is no adequate number of memory deallocations when compared to memory allocations.

0 Kudos
Zhanghong_T_
Novice
666 Views

Dear iliyapolak,

Thank you very much for your kindly reply.

How to make sure that it is adequate number of memory to be deallocated?

Thanks

 

0 Kudos
Bernard
Valued Contributor I
666 Views

You must assure that for every allocation is corresponding memory deallocation otherwise Inspector will probably complain about missing deallocation.

0 Kudos
Zhanghong_T_
Novice
666 Views

Dear iliyapolak,

Thank you very much for your kindly reply.

Do you mean that there could be some allocated memory (idx2faclist ) are not deallocated, and the array is reallocated again next time? Maybe there are such problem, I will check it.

Is it better to write like this?

if(idx2faclist)  delete [] idx2faclist;

idx2faclist = new int[points->items + 1];

...

delete [] idx2faclist;

 

Thank

0 Kudos
Bernard
Valued Contributor I
666 Views

After your code accessed idx2faclist array and it is not needed anymore simply use delete[] operator one time. Compiler will create code which will iterate over whole idx2faclist array and will release the memory probably by calling VirtualFreeEx on Windows.

0 Kudos
Reply