What you show looks OK on the face of it.
Perhaps the DLL is changing the pointer values to null before returning? Are these pointers passed by reference?
Try adding some output in your function to display the before and after values of these pointers as a check. I'd check right after the calls to new and just before delete[], in case any intervening code (including your own) is monkeying with the values.
I have now checked (very carefully) the first and last pointers after creating them, after passing them to the DLL and after trying to delete them.
Once created, the pointers do not change. The values they point to are initially rubbish, then the expected values for [0] after they have been populated, then (a different) rubbish after they have been "deleted". This latter is despite the fact that the Private Working Set does not change.
I have now also discovered that a vector of vectors that I create and clear in the routine is not being deleted either.
When I get out of the routine, the Working Set goes up slightly (8k), which I find surprising.
We tried your approach but it didn't make any obvious difference.
We have been investigating hard and now know a little more about the C++ memory handling system.
Basically C++ doesn't do garbage collection immediately, or even particularly soon. When we reached about 95% of physical memory it started to nibble away at the Working Set, initially it just kep it stable but then, a few minutes later, there were bigger drops.
Meanwhile the Commit increased inexorably, and eventually the program just stopped progressing much at all. Not only was there little CPU activity but there were few page faults either.
I think we have real memory leaks.
It is fustrating because this program was originally written in VB.NET which has memory compaction as well as garbage collection. That version runs indefinitely just fine.
We have been doing a lot of work on this, and now think we may have solvd it. However, a lot of testing is still required because the application has to handle a very wide range of data and we need to be sure that it works in all cases (I only presented a small sub-set of our problem.)
Thank you for your input. I'll get back to you when we know more.