Skip to content

Commit

Permalink
Merge pull request #65 from grisha-kotler/RavenDB-21305-6.0
Browse files Browse the repository at this point in the history
RavenDB-21305 - add a finalizer to TermInfosReader
  • Loading branch information
arekpalinski authored Oct 17, 2023
2 parents 621acd3 + 968cf38 commit b3e1400
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<Version>3.0.60009</Version>
<FileVersion>3.0.60009</FileVersion>
<Version>3.0.60010</Version>
<FileVersion>3.0.60010</FileVersion>
<LangVersion>latest</LangVersion>
<DebugType>embedded</DebugType>

Expand Down
17 changes: 16 additions & 1 deletion src/Lucene.Net/Index/TermInfosReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ public int MaxSkipLevels

public void Dispose()
{
if (isDisposed) return;
if (isDisposed)
return;

GC.SuppressFinalize(this);

// Move to protected method if class becomes unsealed
if (origEnum != null)
Expand All @@ -156,6 +159,18 @@ public void Dispose()

isDisposed = true;
}

~TermInfosReader()
{
// each TermInfosReader holds a cache (ArrayHolder) which is created upon creation of the TermInfosReader instance.
// in the past we created a new ArrayHolder when creating a new TermInfosReader instance.
// if it wasn't disposed, nothing happened since we have a finalizer for the ArrayHolder.
// we changed the implementation and now this cache is shared between different instances of TermInfosReader.
// when TermInfosReader isn't disposed we are still holding a reference to the ArrayHolder.

// releasing the reference for the cached ArrayHolder will match the previous behaviour.
_termsIndexCache?.ReleaseRef();
}

/// <summary>Returns the number of term/value pairs in the set. </summary>
internal long Size()
Expand Down

0 comments on commit b3e1400

Please sign in to comment.