Depending on idispose to close index writer is a slippery slope as it is 
unpredictable when garabage collector will kick in.

In the worst case, you may not be able to add/remove documents to the index if 
some uncollected object is holding the lock on the index.  Cleaner approach is 
to simply close once the maintenance is completed.

-----Original Message-----
From: Kohlhepp, Justin W (Heritage Holdings (HHI)) 
[mailto:justin.kohlh...@thehartford.com] 
Sent: Friday, June 01, 2012 10:48 AM
To: lucene-net-user@lucene.apache.org
Subject: RE: Implementing IDisposable / finalizer pattern to avoid index lock 
issues

Hmm...well my implementation is too layered to allow for a try/catch to 
correctly ensure that IndexWriter.Close is called, so I'm pretty much forced to 
use IDisposable / finalizer.  I'm just surprised that IndexWriter itself 
doesn't do this work.  Generally the expectation is that if a managed class 
manages an unmanaged resource such as a file on disk, that it cleans up after 
itself in a finalizer.

Thanks for the response.  It sounds like I'm not missing anything and this is 
just the way things are.

~ Justin

-----Original Message-----
From: Brian Sayatovic [mailto:bsayato...@creditinfonet.com]
Sent: Friday, June 01, 2012 1:44 PM
To: lucene-net-user@lucene.apache.org
Subject: RE: Implementing IDisposable / finalizer pattern to avoid index lock 
issues

I use a try/finally myself, with some extension methods to wrap it.  My 
understanding is that IDisposable is wrought with trouble.  My Lucene access is 
wrapped in an agent class, and my syntax ends up looking like DoWithAgent(agent 
=> agent.UpdateIndex(foo));

Brian Sayatovic
Senior Software Architect

866-218-1003 toll-free ext. 8936
937-235-8936 office
4540 Honeywell Ct. Dayton, OH 45424


This message may contain confidential/proprietary information from the CINgroup 
or its subsidiaries.
If you are not an intended recipient, please refrain from the disclosure, 
copying, distribution or use of this information. All such unauthorized actions 
are strictly prohibited. If you have received this transmission in error, 
please notify the sender by e-mail and delete all copies of this material from 
any computer.


-----Original Message-----
From: Kohlhepp, Justin W (Heritage Holdings (HHI)) 
[mailto:justin.kohlh...@thehartford.com]

I was surprised to notice that IndexWriter does not implement IDisposable.  It 
seems that the user is responsible for guaranteeing that IndexWriter.Close is 
called and that IndexWriter itself does not do this in a Dispose or destructor 
method.  Do I have this understanding correct?  I wrote a wrapper around 
Lucene.NET for my application and was forced to implement IDisposable / 
finalizer in order for index to unlock correctly.  Is this the expected pattern?
************************************************************
This communication, including attachments, is for the exclusive use of 
addressee and may contain proprietary, confidential and/or privileged 
information.  If you are not the intended recipient, any use, copying, 
disclosure, dissemination or distribution is strictly prohibited.  If you are 
not the intended recipient, please notify the sender immediately by return 
e-mail, delete this communication and destroy all copies.
************************************************************

Reply via email to