Using the Java version of opencv, the camera encountered a memory overflow issue while iteratively fetching images

JDK version:17
opencv version:4.8
When I use the following code loop to obtain camera images, the memory usage will become increasingly high, which will eventually lead to memory overflow. Through experiments, both IMEncode and IMshow methods can lead to this situation.

 MatOfByte mob;
        for (int n = 0; n < 100000; n++) {
            nRet = MvCameraControl.MV_CC_GetImageBuffer(hCamera, stFrameOut, 1000);
            // Get one image
            if (MV_OK == nRet) {
                Mat mat = new Mat(2048, 2448, CvType.CV_8U);
                mat.put(0, 0, stFrameOut.buffer);
//                HighGui.imshow("GigE Camera", mat);
//                HighGui.waitKey(18);
                 mob = new MatOfByte();
                imencode(".jpg", mat, mob);
                byte[] array = mob.toArray();
                s.broadcast(array);
                mob.release();
                mat.release();
                int i = MvCameraControl.MV_CC_FreeImageBuffer(hCamera, stFrameOut);
                if (i != 0) {
                    System.out.println("失败");
                }
                MvCameraControl.MV_CC_ClearImageBuffer(hCamera);
            } else {
                System.err.printf("\n Get ImageBuffer failed, errcode: [%#x]\n", nRet);
            }
            ThreadUtil.sleep(10);
        }