64mp Camera freezes when calling picam2.switch_mode_and_capture_file

Description
Camera freezes whenever I use this code: picam2.switch_mode_and_capture_file(capture_config, “test_full.jpg”)
Although, picam2.capture_file(“test_full.jpg”) works fine. I don’t understand what’s causing this issue. The camera I’m using is Arducam’s 64mp hawkeye camera. I can’t preview in max resolution because buffer allocation fails. The issue is with the swtich_mode code. Whenever my program reaches this part it freezes, then I have to terminate and restart. There are no error messages or crashes whatsoever. I want to use this method to capture full 64mp resolution photos.

Hardware:
RPi 4
Arducam Hawkeye 64 mp

Forgot to mention. The libcamera terminal commands work perfectly, I’ve tested taking photos on multiple resolutions, they work fine.

Also, CMA is big enough. The problem is with the switch_mode function. For example:
This code works fine:
import time

from picamera2 import Picamera2, Preview

picam2 = Picamera2()
picam2.start_preview(Preview.QTGL)

preview_config = picam2.create_preview_configuration()
capture_config = picam2.create_still_configuration()
picam2.configure(preview_config)
picam2.configure(capture_config)

picam2.start()
time.sleep(2)

picam2.capture_file(“test_full.jpg”)
time.sleep(2)

But if I use “switch_mode_and_capture_file(capture_config, “test_full.jpg”)”. That’s when the camera freezes and I have to force stop my program.

@DongHaoRan
Okay, came up with a temporary solution, here is the script:

  import time
  import os
  from picamera2 import Picamera2, Preview

   with Picamera2() as picam2:
      picam2.start()
      time.sleep(5)
      picam2.stop()
      time.sleep(2)



  with Picamera2() as picam3:
      picam3.configure(picam3.create_still_configuration())
      picam3.start()
      time.sleep(2)
      picam3.capture_file("test.jpg")

using ‘with’ statements, frees up the memory for capturing full res. Now I can check the preview, in one 'with. statement and take photo in the other. Also, libcamera works as well if I call it after the end of ‘with’ statement.