Skip to content

new Context() seems to have a memory leak on MacOS #427

@stefanhahmann

Description

@stefanhahmann

The following unit test produces a OutOfMemory Error (Java Heap Space), when being run in MacOS, but not so in Ubuntu:

package sc.fiji;

import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;

class ScijavaContextTest
{
	@Test
	void testContext()
	{
		for ( int i = 0; i < 500; i++ )
			try (org.scijava.Context context = new org.scijava.Context())
			{
			}
		assertTrue( true, "Successfully created and closed 500 contexts without running out of resources." );
	}
}

I created a small repo that exemplifies this: https://github.com/BioImageTools/scijava-context-test/blob/main/src/test/java/sc/fiji/ScijavaContextTest.java

When the pom.xml only contains

<dependency>
	<groupId>org.scijava</groupId>
	<artifactId>scijava-common</artifactId>
</dependency>

the error does not occur: https://github.com/BioImageTools/scijava-context-test/actions/runs/23891816087

However, when the pom.xml contains

<dependency>
	<groupId>sc.fiji</groupId>
	<artifactId>fiji</artifactId>
</dependency>

the error does occurs.

It occurs on MacOS, not on Ubuntu. Windows was not tested.

While this bug may not be so relevant for practical use of Fiji, it is definitly relevant, when running e.g. unit test cases where many new Context() calls may be included.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions