Analyzers
Support for Analyzers (Intel VTune™ Profiler, Intel Advisor, Intel Inspector)
4638 Discussions

How to understand 'Mismatched allocation/deallocation'?

Zhanghong_T_
Novice
201 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
Black Belt
201 Views

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

Zhanghong_T_
Novice
201 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

 

Bernard
Black Belt
201 Views

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

Zhanghong_T_
Novice
201 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

Bernard
Black Belt
201 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.

Reply