bytedeco/javacv

Mat, Imgproc.resize Possible memory leak

オープン

#2,283 opened on 2024/09/15

 (23 件のコメント) (0 件のリアクション) (0 人の担当者)Java (1,583 件のフォーク)batch import
help wantedquestion

Repository metrics

Stars
 (6,985 個のスター)
PR merge metrics
 (PR metrics pending)

説明

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

コントリビューターガイド