[ImageJ-devel] when to close cursors, was Re: [fiji-devel] imglib coding style

Stephan Saalfeld saalfeld at mpi-cbg.de
Thu Apr 15 07:12:09 CDT 2010


Hi,

> right now the Cursor.close() call is not necessary for any of the
> containers. But it will be when we start paging data and each Cursor
> will get a lock on the cell it currently works on. So when writing
> stuff using imglib one should think ahead and close cursors when they
> are not needed anymore. 
> 
> I do not really see how the new design should get rid of that
> paging-lock-cell problem Stephan -  how should it work without
> explicitly closing the cursor so that it releases the cell it is
> currently on when not needed anymore...

As I said---I was tired :)  I thought about not locking cells at all and
delivering a copy of the data for each cursor independently which then
would be deleted automatically on cursor death but that violates data
persistence for many cursors accessing the same data.  So we need an
external instance providing the paged data in a single instance and,
therefore, the close construct.

> It might also be that Cursors have a local cache (which might be again
> an Image) they can empty when they are not needed anymore or that only
> a certain number of Cursors in parallel is allowed for some reason. 
> 

Deleting the cursor the Java way would delete the Cache too, Caches on
container- or image-level would need the close construct though.  For
constraining the number of cursors allowed to run in parallel, I cannot
figure out a proper reason.

Still, Image collects the cursors working on it but never removes them,
this needs to be fixed.

Best,
Stephan


> Ciao ciao,
> Steffi
> 
> > -----Original Message-----
> > From: Stephan Saalfeld [mailto:saalfeld at mpi-cbg.de]
> > Sent: Donnerstag, 15. April 2010 00:34
> > Cc: Johannes Schindelin; preibisch at mpi-cbg.de; fiji-
> > devel at googlegroups.com; Imagejdev.org Developers
> > Subject: Re: when to close cursors, was Re: [fiji-devel] imglib coding
> > style
> > 
> > Hi,
> > 
> > Cursor.hasNext() == false does not mean that the cursor is out of image
> > bounds and, depending on the container may still point to some data.
> > Image keeping track of its cursors, it is good to close them for
> > freeing
> > this data.  Currently, this is important in cell containers only.
> > 
> > I think that the recent design changes regarding data access make this
> > tracking of cursors obsolete and so Cursor.close() too.  A good hint is
> > that Image.removeCursor() is just never called.  But I am very tired
> > and
> > have to check this.
> > 
> > Good night,
> > Stephan
> > 
> > 
> > 
> > 
> > On Wed, 2010-04-14 at 17:10 -0500, Curtis Rueden wrote:
> > > Hi Johannes,
> > >
> > > At the hackathon Steffi told me it is best practice to always close
> > > cursors. I had not done this in SquareTest so I committed a change
> > > that now does so.
> > >
> > > Thanks,
> > > Curtis
> > >
> > > On Wed, Apr 14, 2010 at 4:51 PM, Johannes Schindelin
> > > <Johannes.Schindelin at gmx.de> wrote:
> > >         Hi,
> > >
> > >         while writing a base class for JUnit tests, I realized that I
> > >         did not
> > >         close() the cursors when cursor.hasNext() returned false. Are
> > >         you supposed
> > >         to close() them even then?
> > >
> > >         Ciao,
> > >         Johannes
> > >
> > >
> > >
> 
> 





More information about the ImageJ-devel mailing list