<!DOCTYPE html><html><head><title></title></head><body><div>Thank Evan!</div><div><br></div><div>I am planning on being read-only for now. </div><div><br></div><div>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?</div><div><br></div><div>Here is my understanding for now.  To enumerate layers:</div><div>- open Dataset</div><div>- iterate through Layers</div><div>- close Dataset</div><div><br></div><div>To work with a Layer</div><div>- open Dataset read-only</div><div>- get the Layer object</div><div>- work with it</div><div>- eventually.... close the Dataset</div><div><br></div><div>To work with multiple layers from the same Dataset</div><div>- it is best if each gets it's own read-only Dataset instance</div><div>- in this case each Layer can be read simultaneously from different threads</div><div><br></div><div> 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?</div><div><br></div><div>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?</div><div><br></div><div>Thanks,</div><div>Tom</div><div><br></div><div>On Thu, May 29, 2025, at 1:05 PM, Even Rouault wrote:</div><blockquote type="cite" id="qt" style=""><div>Hi,</div><blockquote type="cite" cite="mid:40a2c286-0557-4eca-b5e4-7723d89c5250@app.fastmail.com"><div><br></div><div>In particular I would like to know more about object life
        cycles and memory management: </div><div>What kind of object management is the client program
        responsible for? </div></blockquote><p>Normally none, but you may want to explicitly call .Close() on
      datasets to ensure the underlying file is closed at the
      appropriate moment</p><blockquote type="cite" cite="mid:40a2c286-0557-4eca-b5e4-7723d89c5250@app.fastmail.com"><div>Do I need to close objects manually or will the garbage
        collector take care of this for me?</div></blockquote><div>for objects other than datasets, GC should work fine</div><blockquote type="cite" cite="mid:40a2c286-0557-4eca-b5e4-7723d89c5250@app.fastmail.com"><div>If I open an OGR Dataset twice will I get two separate
        instances, or will the reference be shared?</div></blockquote><div>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.</div><blockquote type="cite" cite="mid:40a2c286-0557-4eca-b5e4-7723d89c5250@app.fastmail.com"><div><br></div><div>Is this mailing list the place where I should be asking these
        questions, or it there a better place for it?</div></blockquote><p>No, that's fine</p><div>Even<span style="text-wrap-mode:wrap;white-space-collapse:preserve;"></span></div><pre class="qt-moz-signature" cols="72">-- 
<a class="qt-moz-txt-link-freetext" href="http://www.spatialys.com">http://www.spatialys.com</a>
My software is free, but my time generally not.</pre></blockquote><div><br></div></body></html>