bytedeco/javacv

Mat, Imgproc.resize Possible memory leak

Open

#2,283 创建于 2024年9月15日

在 GitHub 查看
 (23 评论) (0 反应) (0 负责人)Java (1,583 fork)batch import
help wantedquestion

仓库指标

Star
 (6,985 star)
PR 合并指标
 (30 天内没有已合并 PR)

描述

Hi Folks,

I’m encountering a possible memory leak while using JavaCV for image resizing in a Spring-WebFlux application.

Environment Details:

  • Kubernetes Pod: 8GB memory
  • JVM Settings: -Xms=1024M, -Xmx=2048M
  • Traffic: ~30 TPS on one pod

Issue: Memory utilization climbs to ~92% over a span of ~30 hours and then stabilises.

  • I’ve ensured that all Mat objects are properly released and also employed PointerScope for memory management.
  • JVM heap memory usage never exceeds 1GB.

Despite these efforts, memory usage continues to rise steadily over time. Below is the snippet of code used for resizing images:

try (PointerScope pointerScope = new PointerScope()) {
    Mat mat = Imgcodecs.imread(inputMediaPath.toString());
    Size size = new Size(width, height);
    Mat resizedMat = new Mat();
    Imgproc.resize(mat, resizedMat, size, 0, 0, Imgproc.INTER_AREA);

    Imgcodecs.imwrite(outputMediaPath.toString(), resizedMat);
    mat.release();
    resizedMat.release();
    // Tried both with and without pointerScope.deallocate(), but memory issues persist.
    pointerScope.deallocate();
}

Any advice on resolving this issue would be greatly appreciated. I’ve tried several approaches but cannot pinpoint the root cause of the rising memory usage.

Thanks in advance for your help!

Best regards, Ravi

贡献者指南