Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RavenDB-21305 - add a finalizer to TermInfosReader #64

Merged
merged 2 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.54010</Version>
<FileVersion>3.0.54010.0</FileVersion>
<Version>3.0.54011</Version>
<FileVersion>3.0.54011.0</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
Loading