Out of heap means also basically out of memory, so for sure you need to free a lot.
I have never seen an out of heap error in 40 odd years, so concrats! you must be one of the first...and doing something very,very wrong, but we do not know what because your info is too scarse.
The heap size itself is usually available physical memory + the available swap space.
(this is not the case for embedded, where the heap can be explicitly defined, depending on system)