'OutofMemoryError' occurs when using Mat(uiImage:)

We are using the iOS framework.
When calling Mat(uiImage:) several times consecutively, the following error occurs

libc++abi: terminating with uncaught exception of type cv::Exception: OpenCV(4.5.5) /Volumes/build-storage/build/master_iOS-mac/opencv/modules/core/src/alloc.cpp:73: error: (-4:Insufficient memory) Failed to allocate 31961088 bytes in function 'OutOfMemoryError'

For example, the same error occurs with the following code

for i in 0..<1000 {
   let testBundle = Bundle(for: type(of: self))
   let imagePath = testBundle.path(forResource: "XXXX", ofType: "jpeg")
   let image = UIImage(contentsOfFile:imagePath!)!
   var mat = Mat(uiImage: image)

We suspect that the memory of Mat is not being released.

Do you know the cause of these issues?
And how can we resolve this?

Hii fumiya , Can you please help me converting an UIImage to Mat type using opencv and vice versa ?