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

Fixed leak in object pool #5521

Merged
merged 1 commit into from
Dec 2, 2020
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
6 changes: 4 additions & 2 deletions src/Microsoft.ML.Data/Data/DataViewUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -942,8 +942,10 @@ public override void Set(BatchColumn batchCol)
public override void Unset()
{
Contracts.Assert(_index <= _count);
if (Values != null)
_pool.Return(Values);
// Remove all the objects from the pool
// to free up references to those objects
while (_pool.Count > 0)
_pool.Get();
Comment on lines -945 to +948
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the original code was a copy paste error. If you look at the code for Set, it has the same if check and the same _pool.Return... _pool.Return actually adds it to the Bag (bad method name? Not intuitive). So I think your fix maxes sense since get is actually removing it from the pool unlike return.

Right now since you are just doing a get, the resources are freed when the GC is run. Would it be better to do something like this?

while (_pool.Count > 0)
{
    var item = _pool.Get();
    (item as IDisposable)?.Dispose();
}

This way if it is disposable it will free it up right away. Not sure if that would impact performance much though.

What are your thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have many disposable objects. The disposable objects we consume are mostly from Tensorflow and OnnxRuntime. These aren't part of the object pool. If we add that line, I can't think of a test we can add that would exercise that code path.


In reply to: 534439391 [](ancestors = 534439391)

Values = null;
_count = 0;
_index = 0;
Expand Down
2 changes: 1 addition & 1 deletion test/Microsoft.ML.TestFramework/BaseTestClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void IDisposable.Dispose()
Cleanup();
Process proc = Process.GetCurrentProcess();
Console.WriteLine($"Finished test: {FullTestName} " +
$"with memory usage {proc.PrivateMemorySize64.ToString("N", CultureInfo.InvariantCulture)}");
$"with memory usage {proc.WorkingSet64.ToString("N", CultureInfo.InvariantCulture)}");
}

protected virtual void Initialize()
Expand Down