Analyzers
Community support for Analyzers (Intel VTune™ Profiler, Intel Advisor, Intel Inspector)
Announcements
The Intel sign-in experience has changed to support enhanced security controls. If you sign in, click here for more information.
4819 Discussions

How to understand 'Mismatched allocation/deallocation'?

Zhanghong_T_
Novice
353 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
353 Views

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

Zhanghong_T_
Novice
353 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
353 Views

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

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