possible memory leak?

Hi,

I think I may have found a memory leak. In HeightmapTesselator.cxx around line 173:

delete _vertex_index;
delete _dirty_vertices;
delete _triangle_totals;

AFAIK, these should use delete[] since they’re arrays.

-Greg

You are right, it should be delete[], otherwise behavior is undefined I think. Have you confirmed the memory leak, though? (Just curious if it actually happens, cause you are right anyway)

I’ll fix it myself. Thanks!

Sorry, I didn’t verify. If it is leaking it should happen every time the terrain is regenerated. I may verify later. I’m also curious what my compiler will do.

-Greg

Technically, C++ only requires the [] operator on delete if you need the destructor to be called on each element of the array. Even without the [] operator, it will still free the array itself correctly.

Since these are arrays of int, which doesn’t require a destructor, there is no memory leak in this case in practice. However, you’re absolutely right about the mistake–it is correct to include the [] operator when deleting an array, and its omission here is an error.

David

Oh okay. Thanks. That’s good to know. :slight_smile: