Skip to content

Memory leak on RetrieveMultipleAsync #463

Description

In the last 3 releases:

  • 1.1.22
  • 1.1.27
  • 1.1.32

The memory leak as described in Issue #207 has returned.

Version 1.1.17 however does not have this issue.

As per #207 this new leak is also only an issue when using RetrieveMultipleAsync, using RetrieveMultiple works as expected

As per [https://github.com//issues/207#issuecomment-983838048](This reply on 207 )
I tested the following and still saw memory consumption continue to rise and never be released:

  • Smaller Batch sizes
  • Pulling from narrow tables, (The example below is using ActivityParty which is only 33 columns wide)

Here is some sample code from a .NET 8.0 Console App which reproduces the issue:

using Microsoft.PowerPlatform.Dataverse.Client;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;

internal class Program
{
    private static async Task Main(string[] args)
    {
        string InstanceURL = "<Dynamics URL Here>";
        string ClientId = "<ClientId Here>";
        string ClientSecret = "<ClientSecret Here>";

        ServiceClient.MaxConnectionTimeout = TimeSpan.FromMinutes(60);
        ServiceClient client = new ServiceClient($"AuthType=ClientSecret; Url={InstanceURL}; ClientId={ClientId}; ClientSecret={ClientSecret}")
        {
            EnableAffinityCookie = false,
        };

        QueryExpression query = new()
        {
            PageInfo = new PagingInfo
            {
                PagingCookie = "",
                PageNumber = 1,
                Count = 5000,
            },
            EntityName = "activityparty",
            Distinct = false,
            NoLock = true,
            ColumnSet = new ColumnSet(true),
        };

        bool MoreRecords = false;
        long TotalCount = 0;
        do
        {
            EntityCollection QueryResult = await client.RetrieveMultipleAsync(query);
            TotalCount += QueryResult?.Entities?.Count ?? 0;
            MoreRecords = QueryResult?.MoreRecords ?? false;
            if (MoreRecords)
            {
                query.PageInfo.PagingCookie = QueryResult?.PagingCookie ?? string.Empty;
                query.PageInfo.PageNumber++;
            }
        }
        while (MoreRecords);

        Console.WriteLine($"Downloaded {TotalCount:N0} Records");
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions