and MeshGrid::CalculateGridLength(unsigned long, unsigned long)
For almost flat meshes CalculateGridLength may compute a grid with a huge amount of cells that allocates the whole RAM of the system while for an exactly flat mesh a grid with a sensible number of cells is computed.
Use the overloaded methods of MeshGrid::Rebuild(unsigned long) and MeshGrid::CalculateGridLength(unsigned long) instead