Running out of memory - crippling problem!

I’m nearing a complete project. My available free Ram on the ESP32 varies between 68Kb and 90Kb
when reported by heap_caps_print_heap_info(MALLOC_CAP_DEFAULT);
This is more than enough for my program, but on occasion, it dips just below the required
mybuf = (uint8_t *) heap_caps_malloc(3 * size * sizeof(uint8_t), MALLOC_CAP_DMA)
that is 3 X 480X320 = 460800 bits required, thus a free continuous block of memory of 57600kB
This is on the edge of my available memory, and the driver instead of failing silently and trying again later, just crashes the system due to failed memory allocation.
It would be great if it could sense such a situation, and perhaps then only use half of the memory or something to that effect.

The Code from the tft driver I’m using:

void ili9488_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map)
    uint32_t size = lv_area_get_width(area) * lv_area_get_height(area);

    lv_color16_t *buffer_16bit = (lv_color16_t *) color_map;
    uint8_t *mybuf;
    do {
        mybuf = (uint8_t *) heap_caps_malloc(3 * size * sizeof(uint8_t), MALLOC_CAP_DMA);
        if (mybuf == NULL)  ESP_LOGW(TAG, "Could not allocate enough DMA memory!");
    } while (mybuf == NULL);

    uint32_t LD = 0;
    uint32_t j = 0;

    for (uint32_t i = 0; i < size; i++) {
        LD = buffer_16bit[i].full;
        mybuf[j] = (uint8_t) (((LD & 0xF800) >> 8) | ((LD & 0x8000) >> 13));
        mybuf[j] = (uint8_t) ((LD & 0x07E0) >> 3);
        mybuf[j] = (uint8_t) (((LD & 0x001F) << 3) | ((LD & 0x0010) >> 2));

	/* Column addresses  */
	uint8_t xb[] = {
	    (uint8_t) (area->x1 >> 8) & 0xFF,
	    (uint8_t) (area->x1) & 0xFF,
	    (uint8_t) (area->x2 >> 8) & 0xFF,
	    (uint8_t) (area->x2) & 0xFF,

	/* Page addresses  */
	uint8_t yb[] = {
	    (uint8_t) (area->y1 >> 8) & 0xFF,
	    (uint8_t) (area->y1) & 0xFF,
	    (uint8_t) (area->y2 >> 8) & 0xFF,
	    (uint8_t) (area->y2) & 0xFF,

	/*Column addresses*/
	ili9488_send_data(xb, 4);

	/*Page addresses*/
	ili9488_send_data(yb, 4);

	/*Memory write*/

	ili9488_send_color((void *) mybuf, size * 3);

I have assigned 32Kb for use by LVGL lv_mem_alloc in KConfig.
When monitoring this usage in offending routine, reports on overlay left bottom of screen:

9.6kB used (31%)
4% frag

When I do some more memory intensive calculations, the largest free continuous block of memory will rarely drop just below the required 57600kB, resulting in a crash.
I have checked as mush as possible for unnecessary heap memory usage, and have checked for memory leaks and resolved a few, but due to my app being on the large side, I’m now running into this edge case.

Any advice will help with this crippling problem.
Thx in advance.

This is discussed here:

What MCU/Processor/Board and compiler are you using?

VSCode, ESP-IDF, ESP32-Wroom-32E-Devkit4, IL9488 480x320, FT6X06
I’m using [lv_port_esp32 @ 557679a6]