How to understand 'Mismatched allocation/deallocation'?

How to understand 'Mismatched allocation/deallocation'?

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

6 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

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

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

 

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

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

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.

Leave a Comment

Please sign in to add a comment. Not a member? Join today