[gdal-dev] Java bindings to gdal/ogr - looking for more developer documentation

Tom Moore tmoore at spatial.ca
Thu May 29 12:08:19 PDT 2025


Thank Evan!

I am planning on being read-only for now. 

My program is interactive and potentially long-lived, and the user interface can be used to open layers at different times. If I miss closing a Dataset will the garbage collector eventually take care of this?  Or is it important to always call Close() to release native resources?

Here is my understanding for now.  To enumerate layers:
- open Dataset
- iterate through Layers
- close Dataset

To work with a Layer
- open Dataset read-only
- get the Layer object
- work with it
- eventually.... close the Dataset

To work with multiple layers from the same Dataset
- it is best if each gets it's own read-only Dataset instance
- in this case each Layer can be read simultaneously from different threads

My program is multi-threaded.  Do you think that I will be safe if I use Java synchronization to prevent simultaneous access to a single layer by different threads?  In other words, thread A does a read on Layer 1, then thread B does a read on Layer 1, but neither can do a read at the same time.  Is this OK?

I wont be doing any updates, but I may create new layers.  If so I will open a new Dataset and use to create layer and add Features, and then close it again.  There may be other Dataset object open read-only on the same underlying storage (e.g. the same GeoPackage or FileGDB) at the same time.  Will this be OK?

Thanks,
Tom

On Thu, May 29, 2025, at 1:05 PM, Even Rouault wrote:
> Hi,
>> 
>> In particular I would like to know more about object life cycles and memory management: 
>> What kind of object management is the client program responsible for? 
> Normally none, but you may want to explicitly call .Close() on datasets to ensure the underlying file is closed at the appropriate moment
> 
>> Do I need to close objects manually or will the garbage collector take care of this for me?
> for objects other than datasets, GC should work fine
>> If I open an OGR Dataset twice will I get two separate instances, or will the reference be shared?
> unless you call Dataset.OpenEx() with the GDAL_OF_SHARED flag set, you'll get separate instances. And be careful if using shared instances: you cannot use them concurrently from different threads. If you work with separate instances, (for read-only operations) that should be fine.
>> 
>> Is this mailing list the place where I should be asking these questions, or it there a better place for it?
> No, that's fine
> 
> Even
> -- 
> http://www.spatialys.com
> My software is free, but my time generally not.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20250529/20937cea/attachment.htm>


More information about the gdal-dev mailing list