[ 
https://issues.apache.org/jira/browse/LUCENENET-511?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13467583#comment-13467583
 ] 

Maximilian Haru Raditya commented on LUCENENET-511:
---------------------------------------------------

What do you mean by "IndexWriter wasn't disposed by your finalizer 
(destructor)"? Did you mean I have to _manually_ call my finalizer? How am I 
supposed to do that? Isn't GC that's supposed to do that?

IC. I didn't know about FileStream.Lock() before.
Reading from here: http://wiki.apache.org/lucene-java/LuceneFAQ, it's said that:
{quote}
*What is the purpose of write.lock file, when is it used, and by which classes?*
 
The write.lock is used to keep processes from concurrently attempting to modify 
an index. 

It is obtained by an IndexWriter while it is open, and by an IndexReader once 
documents have been deleted and until it is closed. 
{quote}
So based on what you said and the definition above, do I correctly understand 
that "write.lock" has no meaning in Lucene.Net, as opposed in Lucene? Or it's 
actually still being used?
If that's so, then is it safe for me to assume that the index would be just 
fine, even in case IndexWriter didn't get properly disposed?

Yes, after I was stuck with the non-working, non-deterministic approach, I 
immediately switched back to the deterministic approach. And it works just fine.
It's just that I'm exploring the non-deterministic side at the moment. And I 
have a concern about its reliability. And it doesn't seem to be reliable. And 
it's disappointing actually... :( I thought I could rely on GC in case I forget 
to do the deterministic approach.

BTW, sorry for having so many questions... :D
Just consider me a newbie in this Lucene.Net world. So far it works just fine, 
and the search performance is excellent!
It's just I have an extra concern about reliability. I don't like to see 
something that fail and/or work unreliably.
                
> ObjectDisposedException thrown when IndexWriter disposed by finalizer
> ---------------------------------------------------------------------
>
>                 Key: LUCENENET-511
>                 URL: https://issues.apache.org/jira/browse/LUCENENET-511
>             Project: Lucene.Net
>          Issue Type: Bug
>          Components: Lucene.Net Core
>    Affects Versions: Lucene.Net 3.0.3
>         Environment: Windows 7 x64, .NET Framework 4.5
>            Reporter: Maximilian Haru Raditya
>
> I'm having an issue of ObjectDisposedException with an error message "Cannot 
> access a closed file." when working IndexWriter.
> I manage to reproduce it when I create a new WPF (4.5) app and install 
> 3.0.3-RC2 from NuGet. I then create a LuceneManager which implements 
> IDisposable, and I create a finalizer for it. I wrap IndexWriter inside it, 
> and dispose it inside Dispose(bool). The implementation code looks like this:
> {code}
> namespace WpfApplication
> {
>     using System;
>     using System.Collections.Generic;
>     using System.IO;
>     using Lucene.Net.Analysis.Standard;
>     using Lucene.Net.Index;
>     using Lucene.Net.Store;
>     using Version = Lucene.Net.Util.Version;
>     public class LuceneManager : IDisposable
>     {
>         public static readonly string IndexPath =
>             Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Index");
>         private IndexWriter _indexWriter;
>         private bool _isDisposed;
>         public LuceneManager()
>         {
>             var directory = FSDirectory.Open(IndexPath);
>             var analyzer = new StandardAnalyzer(Version.LUCENE_30, new 
> HashSet<string>());
>             this._indexWriter = new IndexWriter(directory, analyzer, 
> IndexWriter.MaxFieldLength.UNLIMITED);
>         }
>         ~LuceneManager()
>         {
>             this.Dispose(false);
>         }
>         public void Dispose()
>         {
>             this.Dispose(true);
>             GC.SuppressFinalize(this);
>         }
>         private void Dispose(bool isDisposing)
>         {
>             if (!this._isDisposed)
>             {
>                 if (this._indexWriter != null)
>                 {
>                     this._indexWriter.Dispose();
>                 }
>                 this._indexWriter = null;
>                 this._isDisposed = true;
>             }
>         }
>     }
> }
> {code}
> And the calling code looks like this:
> {code}
> namespace WpfApplication
> {
>     using System.Windows;
>     public partial class MainWindow : Window
>     {
>         public MainWindow()
>         {
>             this.InitializeComponent();
>         }
>         private void OnLoaded(object sender, RoutedEventArgs e)
>         {
>             var lucenceManager = new LuceneManager();
>         }
>     }
> }
> {code}
> The app run just fine until I close it and it throws ObjectDisposedException 
> as described above.
> The exception details:
> {code}
> System.ObjectDisposedException was unhandled
>   HResult=-2146232798
>   Message=Cannot access a closed file.
>   Source=mscorlib
>   ObjectName=""
>   StackTrace:
>        at System.IO.__Error.FileNotOpen()
>        at System.IO.FileStream.get_Length()
>        at Lucene.Net.Store.NativeFSLock.Release()
>        at Lucene.Net.Index.IndexWriter.CloseInternal(Boolean waitForMerges)
>        at Lucene.Net.Index.IndexWriter.Dispose(Boolean disposing, Boolean 
> waitForMerges)
>        at Lucene.Net.Index.IndexWriter.Dispose(Boolean waitForMerges)
>        at Lucene.Net.Index.IndexWriter.Dispose()
>        at WpfApplication.LuceneManager.Dispose(Boolean isDisposing)
>        at WpfApplication.LuceneManager.Finalize()
>   InnerException: 
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to