Standard_OutOfMemory
Standard_OutOfMemory is an Open CASCADE Technology (OCCT) runtime exception thrown when the memory manager fails to allocate a requested heap buffer or when an excessive memory request is issued. It is explicitly designed in TKernel to be raised without dynamic heap allocation so that out-of-memory states can be trapped safely.
In Open CASCADE Technology (OCCT), Standard_OutOfMemory is an exception class declared in the Standard package of the core TKernel toolkit. It derives from Standard_ProgramError, which in turn inherits from Standard_Failure, Standard_Transient, and the standard C++ std::exception interface. Unlike most standard OCCT exception types that are instantiated through the DEFINE_STANDARD_EXCEPTION macro, Standard_OutOfMemory is defined with a dedicated implementation that avoids performing dynamic heap allocations when creating and throwing the exception object. Under critical low-memory conditions, attempting to allocate heap memory for exception objects or descriptive error strings would cause recursive allocation failures and abort the process. To guarantee safe exception propagation and stack unwinding, Standard_OutOfMemory uses static singleton allocation mechanisms (via NewInstance()) and maintains a fixed internal buffer for diagnostic messages. Catching this exception indicates that an internal allocator in OCCT, a collection container, or an underlying geometric modeling algorithm was unable to obtain the required memory from the operating system or system allocator.
Open CASCADE Technology raises Standard_OutOfMemory in several common situations: 1. Host Memory or Virtual Address Exhaustion: Core OCCT memory managers (such as Standard_MMgrOpt, Standard_MMgrRaw, or Standard_MMgrTBBalloc) call the system allocator (malloc, calloc, or virtual memory APIs), which returns a null pointer due to physical RAM or virtual address space depletion. 2. Excessive or Overflowing Allocation Size: An arithmetic overflow or invalid size parameter calculates a disproportionate buffer size (for example, attempting to allocate (Standard_Size)-1 or std::numeric_limits<Standard_Size>::max() bytes), triggering an immediate failure in Standard::Allocate. 3. Overly Dense Tessellation: Algorithms such as BRepMesh_IncrementalMesh run with excessively fine linear or angular deflection parameters on complex shapes, generating millions of mesh nodes and triangles that overwhelm available system memory. 4. Deep Topological Data Growth: Complex Boolean operations (BOPAlgo_BOP, BRepAlgoAPI_Fuse), extensive shape healing operations, or large assembly STEP/IGES translations build massive data structures and retain unpruned intermediate TopoDS_Shape and TDocStd_Document references. 5. Direct Raise Invocations: Upstream OCCT algorithms or user modules explicitly call Standard_OutOfMemory::Raise(...) when internal allocation thresholds or container capacity limits are violated.
#include <Standard_OutOfMemory.hxx>
#include <Standard_Failure.hxx>
#include <Standard.hxx>
#include <iostream>
#include <limits>
int main()
{
try
{
// Request an allocation size exceeding virtual memory limits to trigger Standard_OutOfMemory
const Standard_Size impossibleSize = (std::numeric_limits<Standard_Size>::max)();
Standard_Address ptr = Standard::Allocate(impossibleSize);
// Cleanup if allocation unexpectedly succeeds
Standard::Free(ptr);
}
catch (const Standard_OutOfMemory& e)
{
std::cerr << "Caught Standard_OutOfMemory: " << e.GetMessageString() << std::endl;
return 1;
}
catch (const Standard_Failure& e)
{
std::cerr << "Caught Standard_Failure: " << e.GetMessageString() << std::endl;
return 2;
}
return 0;
}
Validate and constrain allocation parameters before calling OCCT memory routines, optimize meshing deflection parameters, and ensure unused CAD topologies are released so OCCT Handle smart pointers can reclaim memory.
```cpp
#include <Standard_OutOfMemory.hxx>
#include <Standard_Failure.hxx>
#include <Standard.hxx>
#include <iostream>
int main()
{
// Establish a bounded, validated buffer size
const Standard_Size validSize = 1024;
const Standard_Size maxAllowedSize = 100 * 1024 * 1024; // 100 MB safe threshold
if (validSize > maxAllowedSize)
{
std::cerr << "Error: requested size exceeds safety threshold." << std::endl;
return 1;
}
try
{
Standard_Address ptr = Standard::Allocate(validSize);
if (ptr != nullptr)
{
std::cout << "Successfully allocated " << validSize << " bytes with Standard::Allocate." << std::endl;
Standard::Free(ptr);
}
}
catch (const Standard_OutOfMemory& e)
{
std::cerr << "Standard_OutOfMemory handled: " << e.GetMessageString() << std::endl;
return 1;
}
return 0;
}
```
Open CASCADE Technology OCCT 7.8.0 — Standard_OutOfMemory.hxx — retrieved 2026-08-11
Open CASCADE Technology Reference Manual: Package Standard
Open CASCADE Technology User Guide: Foundation Classes - Memory Management