Memory management when using Vault web services

Memory management when using Vault web services

ppauleSHGR6
Enthusiast Enthusiast
89 Views
0 Replies
Message 1 of 1

Memory management when using Vault web services

ppauleSHGR6
Enthusiast
Enthusiast

Hi all,

 

I am developing a standalone app that uses the Vault web services to create and update items.

The problem is, that it is piling up memory and doesn't release it anymore.

The app should run 24/7 because it creates and updates items in the background like a job server.

At the moment I am targeting Vault Professional 2023.

 

I am using the "WebServiceManager" as a singleton in my code.

The log in is made only once, after that the instance of the "WebServiceManager" is re-used all the time while the app is running.

 

There are a lot of Autodesk processs started in the background and I am wondering if this could be the issue.

With each item that is created/updated the memory usage increases and more and more Autodesk processes are being started in the background.

 

ppauleSHGR6_0-1753871923188.png

 

So far I was not able to find or could think of any other reason for the increasing memory usage in my code.

 

Basically this is my code (a little bit simplified):

private WebServiceManager GetWebService()
{
    if (this.m_serviceManager != null)
        return this.m_serviceManager;

    WebServiceManager serviceManager = null;
    try
    {
		if (this.AuthViaAutodeskAccount)
		{
			VDF.Vault.Results.LogInResult results = VDF.Vault.Library.ConnectionManager.LogIn(this.VaultServer, this.VaultTresor, this.VaultUsername, this.VaultPassword, VDF.Vault.Currency.Connections.AuthenticationFlags.Standard, null);
			if (!results.Success)
				return null;

			if (results.Connection != null && results.Connection.WebServiceManager != null)
				serviceManager = results.Connection.WebServiceManager;
		}
		else
		{
			ServerIdentities serverIdentity = new ServerIdentities()
			{
				DataServer = this.VaultServer,
				FileServer = this.VaultFileServer
			};

			WebServiceManager.AllowUI = false;
			LicenseManager.Instance.SetActive();

			UserPasswordCredentials login = new UserPasswordCredentials(serverIdentity, this.VaultTresor, this.VaultUsername, this.VaultPassword);
			serviceManager = new WebServiceManager(login);
		}
    }
    catch (Exception)
    {
        throw;
    }
    return serviceManager;
}

public bool CreateItem(string ItemNumber, string ItemTitle, string CategoryName, string NumSchemName)
{
    bool retVal = false;

    try
    {
		this.m_serviceManager = this.GetWebService();
		ProductRestric[] restrictions;        

        Cat[] categoriesByEntityClassId = this.m_serviceManager.CategoryService.GetCategoriesByEntityClassId("ITEM", true);
        Cat category = categoriesByEntityClassId.FirstOrDefault(x => string.Equals(x.Name, CategoryName, StringComparison.OrdinalIgnoreCase));

        Item item = this.m_serviceManager.ItemService.AddItemRevision(category.Id);
        StringArray[] fieldInputs = new StringArray[1];
        StringArray sarray = new StringArray()
        {
            Items = new string[] { ItemNumber }
        };
        fieldInputs[0] = sarray;
        ItemNum[] itemNum = this.m_serviceManager.ItemService.AddItemNumbers(new long[] { item.MasterId }, new long[] { this.GetNumSchemaId(NumSchemName) }, fieldInputs, out restrictions);
        if (restrictions == null || restrictions.Length == 0)
        {
            item.Title = ItemTitle;
            item.ItemNum = itemNum[0].ItemNum1;

            this.m_serviceManager.ItemService.UpdateAndCommitItems(new Item[] { item });
            retVal = true;
        }
        else
        {
            ProductRestricCode code = restrictions[0].Code;
            throw new Exception(code);
        }
    }
    catch (Exception ex)
    {
		throw;
    }
    finally
    {
        try
        {
            this.m_serviceManager.ItemService.DeleteUncommittedItems(false);
        }
        catch (Exception)
        {
        }
    }
    return retVal;
}

public bool EditItem(string ItemNumber, string ItemRevision, string ItemTitle)
{
    bool retVal = false;

    try
    {
		this.m_serviceManager = this.GetWebService();
	
        ItemService itemSvc = this.m_serviceManager.ItemService;
        Item item = ItemRevision == string.Empty ? itemSvc.GetLatestItemByItemNumber(ItemNumber) : itemSvc.GetItemByItemNumberAndRevisionNumber(ItemNumber, ItemRevision);
		
        if (item != null)
        {
            item = itemSvc.EditItems(new long[] { item.RevId }).First<Item>();
            item.Title = ItemTitle;
        }
		
        if (item == null)
			throw new Exception($"Item {ItemNumber} not found");
		
		itemSvc.UpdateAndCommitItems(new Item[] { editableItem });
		retVal = true;
    }
    catch (Exception ex)
    {
        throw;
    }
    finally
    {
        try
        {
            this.m_serviceManager.ItemService.DeleteUncommittedItems(false);
        }
        catch (Exception)
        {
        }
    }
    return retVal;
}

 

Maybe I am doing something wrong?

 

Any help or advice is really much appreciated - thanks!

0 Likes
90 Views
0 Replies
Replies (0)