Skip to content

Off-Heap native memory leak #55

Closed
Closed
@JayanWarden

Description

@JayanWarden

I am experiencing an off-heap memory leak in my test application.
When reading many images, Heap size stays well below the max heap configured for the Application (for example 4GB), but when processing many HEIF images, java commit size grows into the tens of GBs of memory. The JVM dies after a while, because it cannot allocate more memory, as well as other applications on the PC due to memory starvation of the whole system.

imageio-common-0.6.2
imageio-heif-0.6.2
imageio-core-3.10.1
libheif 1.14
OpenJDK 21.0.3.9-hotspot

It is easy to reproduce with this test program:

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.imageio.stream.ImageInputStream;

import com.github.gotson.nightmonkeys.heif.imageio.plugins.HeifImageReader;
import com.github.gotson.nightmonkeys.heif.imageio.plugins.HeifImageReaderSpi;

public class HEIFReadLoop {

	private HeifImageReaderSpi heifSpi = new HeifImageReaderSpi();
	private HeifImageReader reader;

	public static void main(String[] args) {
		HEIFReadLoop l = new HEIFReadLoop();
	}

	public HEIFReadLoop() {
		try {
			reader = (HeifImageReader) heifSpi.createReaderInstance();
			int counter = 0;
			while (true) {
				System.out.println("read image " + counter++);
				BufferedImage image = readHeicImage(new File("test.heic"));
			}
		} catch (IOException e) {
			e.printStackTrace();
			return;
		}
	}

	private BufferedImage readHeicImage(File file) throws IOException {
		try (ImageInputStream input = ImageIO.createImageInputStream(file)) {
			reader.reset();
			reader.setInput(input);
			BufferedImage result = reader.read(0);
			reader.dispose();
			return result;
		}
	}

}

Run with -Xmx256m given a sufficiently small .heic image.
When you run this test app, Heap size stays well below 256m for a small image.
But system memory used by the java process grows by about 150m each second, untill all available system RAM is consumed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    releasedIssue has been released

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions