NOTICE! This is a static HTML version of a legacy ImageJ Trac ticket.

The ImageJ project now uses GitHub Issues for issue tracking.

Please file all new issues there.

Ticket #566 (closed defect: fixed)

Opened 2011-06-03T16:03:51-05:00

Last modified 2011-06-07T10:15:40-05:00

IJ2 Datasets are not always getting deleted

Reported by: bdezonia Owned by: bdezonia
Priority: major Milestone: biweekly-2011: Jun-06 to Jun-17
Component: Data Model Version:
Severity: serious Keywords:
Cc: Blocked By:


Datasets do not seem to go away always. A scenario that shows this:

open sample clown
convert type to 12-bit unsigned
convert type back to Color RGB
close window

if you use debugger to inspect LegacyPlugin preharmonization() code you can see that old Datasets are sitting around with no associated ImagePlus and it recreates multiple data matching ImagePluses needlessly.

Is it possible that I need to worry about setTempCurrentImage() not getting undone after plugin run? Or some ImagePlus is sitting in LegacyMap that needs to be unregistered and since its not it maintains a link to a Dataset? Or somehow the deleted event is not propagating correctly.

Note - at some point I broke the 12-bit 3 channel Image getting converted back to an ImagePlus by the IJ1 plugin. So this bug may not be testable at the moment. Please leave open until Barry can recreate the bug or determine its fixed.

Change History

comment:1 Changed 2011-06-06T15:23:35-05:00 by bdezonia

Pinned down and worked with Curtis to find solution. Initial commit on b158e60b6f14f8355f755204274ed4f9beb56147.

Now there is an outstanding issue. Open Clown. Open Blobs. Close Clown. Exception thrown (see below). Can continually duplicate by alternating opening one and then deleting the other.

Exception: (related to ConcurrentModificationException in LegacyImageMap)

[WARN ] Exception thrown by;EventService subscriber:imagej.legacy.LegacyImageMap$1@1e9e5c73. Subscriber class:class imagej.legacy.LegacyImageMap$1
org.bushe.swing.exception.SwingException: Exception handling event topic event,, topic=null, eventObj=null
org.bushe.swing.exception.SwingException: Exception handling event topic event,, topic=null, eventObj=null

at org.bushe.swing.event.ThreadSafeEventService.handleException(
at org.bushe.swing.event.ThreadSafeEventService.handleException(
at org.bushe.swing.event.ThreadSafeEventService.publish(
at org.bushe.swing.event.SwingEventService.publish(
at org.bushe.swing.event.ThreadSafeEventService.publish(
at org.bushe.swing.event.EventBus.publish(
at imagej.event.Events.publish(
at imagej.display.AbstractDisplayView.dispose(
at imagej.ui.swing.display.SwingImageDisplay$1.windowClosed(
at java.awt.AWTEventMulticaster.windowClosed(
at java.awt.AWTEventMulticaster.windowClosed(
at java.awt.Window.processWindowEvent(
at javax.swing.JFrame.processWindowEvent(
at java.awt.Window.processEvent(
at java.awt.Component.dispatchEventImpl(
at java.awt.Container.dispatchEventImpl(
at java.awt.Window.dispatchEventImpl(
at java.awt.Component.dispatchEvent(
at java.awt.EventQueue.dispatchEventImpl(
at java.awt.EventQueue.access$000(
at java.awt.EventQueue$
at java.awt.EventQueue$
at Method)
at java.awt.EventQueue$
at java.awt.EventQueue$
at Method)
at java.awt.EventQueue.dispatchEvent(
at java.awt.EventDispatchThread.pumpOneEventForFilters(
at java.awt.EventDispatchThread.pumpEventsForFilter(
at java.awt.EventDispatchThread.pumpEventsForHierarchy(
at java.awt.EventDispatchThread.pumpEvents(
at java.awt.EventDispatchThread.pumpEvents(

Caused by: java.util.ConcurrentModificationException

at java.util.WeakHashMap$HashIterator.nextEntry(
at java.util.WeakHashMap$
at imagej.legacy.LegacyImageMap.unregisterDataset(
at imagej.legacy.LegacyImageMap$1.onEvent(
at imagej.legacy.LegacyImageMap$1.onEvent(
at org.bushe.swing.event.ThreadSafeEventService.publish(
... 35 more

comment:2 Changed 2011-06-06T15:26:43-05:00 by bdezonia

Made all access to the imageMap within LegacyImageMap synchronized. This did not fix the issue.

comment:3 Changed 2011-06-07T09:54:49-05:00 by bdezonia

Fixed in b4dc108f515eab63c9d1a911d44f4bc23117b91c. Using ConcurrentHashMap instead of WeakHashMap. Also specifically telling IJ1 to throw away ImagePluses when their Datasets have been deleted.

There is some question as to whether Datasets not associated with Displays are being left around and have IJ1 resources tied to them. Somewhere we may need to go through the LegacyImageMap calling unregisterDataset() over and over. Must think where this makes sense to do.

comment:4 Changed 2011-06-07T10:15:40-05:00 by bdezonia

  • Status changed from new to closed
  • Resolution set to fixed

Inspection seems to show that Datasets only register with the ObjectManager when they are tied to a Display. Only those displayed Datasets are ever translated to ImagePluses and sent to IJ1. Thus as they themselves become irrelevant they free up IJ1 ImagePluses too. There is no case where undisplayed Datasets are getting ImagePluss associated with them that never get released.