Skip to content

Script language environments should be released #79

Open

Description

@hinerm

Running a simple script in the Fiji script editor:

#@ DatasetIOService dios
#@ String(value="Select file", visibility="MESSAGE") dragNdrop;
#@ File inputFile
#@ UIService ui

testImg = dios.open(inputFile.getPath())

ui.show(testImg)

with a large dataset, memory usage showed persistent growth over time (clicking on status bar didn't free memory). Even after the script editor and image are closed.

Either the engine or the bindings need to be released

Image

Activity

  1. added a commit that references this issue on Nov 16, 2026
    6ab27d5
  2. tferr commented on Nov 16, 2026

    @tferr
    Collaborator

    I am convinced this is fixed in #81 TextEditor has module and scriptInfo fields. These were never cleared after a normal run. Now they are unless the REPL mode is active. Closing it for now. Let's re-open it if the issue persists

  3. added a commit that references this issue on Nov 16, 2026
  4. hinerm commented on Nov 17, 2026

    @hinerm
    MemberAuthor

    The memory leak persists at least in the groovy script language. Using the above script and an 8GB image resulted in memory remaining claimed after closing the script editor.

    The path to GC root goes to the script engine itself so the fix has to go through there.

  5. reopened this on Nov 17, 2026
  6. tferr commented on Nov 17, 2026

    @tferr
    Collaborator

    @hinerm , This will nuke everything started by the script. E.g, this used to work, and it will now throw a MissingPropertyException:

    import javax.swing.*
    import java.awt.event.*
    
    counter = 0
    data = [1, 2, 3]
    
    def frame = new JFrame("Bindings Release Test")
    def buttonLabel = new JLabel(" Button: Click after the run has finished ")
    def workerLabel = new JLabel(" Worker: waiting 3 s... ")
    def button = new JButton("Read script variable")
    
    // Test 1: a listener that outlives the run
    button.addActionListener({ e ->
        try {
            counter++
            buttonLabel.text = "Button: OK (counter=" + counter + ")"
        } catch (Throwable t) {
            buttonLabel.text = "Button: FAILED (" + t.class.simpleName + ")"
        }
    } as ActionListener)
    
    // Test 2: A thread reading a variable after the script has returned
    Thread.start("bindings-worker") {
        Thread.sleep(3000)
        def msg
        try {
            msg = "Worker: OK (data=" + data + ")"
        } catch (Throwable t) {
            msg = "Worker: FAILED (" + t.class.simpleName + ")"
        }
        SwingUtilities.invokeLater { workerLabel.text = msg }
    }
    
    def panel = new JPanel(new java.awt.GridLayout(0, 1, 4, 4))
    panel.add(buttonLabel)
    panel.add(workerLabel)
    panel.add(button)
    frame.add(panel)
    frame.pack()
    frame.setVisible(true)
    
    return null; // 

    Some of the own Fiji example scripts demo how to attach listeners to an image, so at least those will brake. But maybe, it is not a frequent use case?

    Otherwise this would require some sort of preference checkbox in the Run menu that switches the clearing off entirely!? when on: everything works at the risk of memory problems. When off: Fixes #79 for everyone but more interactive scripts with callbacks or threads will break

  7. ctrueden commented on Nov 17, 2026

    @ctrueden
    Member

    I don't understand the example script in the issue report. Are you saying memory is not freed even after the shown image is closed again, due to persistent bindings? Can we make an MCVE that doesn't interact with SCIFIO's on-demand loading (like maybe it just allocates some big array)?

  8. reopened this on Nov 17, 2026
  9. hinerm commented on Nov 17, 2026

    @hinerm
    MemberAuthor

    I reverted the binding release commit and reopened the issue for now.

    @ctrueden correct. it's not an issue with SCIFIO; I included the heap dump to show that there is a clear path from the script bindings that prevents garbage collection of the image.

    I can't reproduce the issue with large array allocation because

    double[] data = new double[1_000_000_000]
    

    tries to process data as an output and produces an exception. Changing it to:

    double[] data = new double[1_000_000_000]
    
    String g = "hello"
    

    doesn't reproduce the issue so presumably it is an interaction with script inputs/outputs + the engine bindings specifically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions