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

feat: change to singleton instance for TdsParser.cs and TdsParserStat… #2420

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

javiermendozain
Copy link

@javiermendozain javiermendozain commented Mar 20, 2024

Change to singleton instance for TdsParser.cs and TdsParserStateObjectManaged.cs, TdsParserStateObjectNative.cs to reduce memory leaks for those objects.

Evidence:

Before the changes, each execution generated instances of TdsParser and TdsParserStateObjectManaged, which remained unused in memory, leading to a memory leak.
Before changes
before changes

This memory leak was observed in services deployed on k8s with Linux pods.
Memory leak
memory leak


After the changes, each execution reused the objects TdsParser and TdsParserStateObjectManaged.
After changes
after changes

after changes pods

…eObjectManaged.cs, TdsParserStateObjectNative.cs to reduce memory leak for those objects
@javiermendozain
Copy link
Author

@dotnet-policy-service agree company="Siigo SAS"

@javiermendozain
Copy link
Author

@javiermendozain please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@dotnet-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@dotnet-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@dotnet-policy-service agree company="Microsoft"

Contributor License Agreement
@dotnet-policy-service agree company="Siigo SAS"

@@ -209,6 +209,9 @@ internal TdsParser(bool MARS, bool fAsynchronous)
DataClassificationVersion = TdsEnums.DATA_CLASSIFICATION_NOT_ENABLED;
}

public static TdsParser Instance(bool MARS, bool fAsynchronous)
=> new TdsParser(MARS, fAsynchronous);

Choose a reason for hiding this comment

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

I'm probably missing something, but every time this method is called it's going to return a new instance of TdsParser.

@Wraith2
Copy link
Contributor

Wraith2 commented Mar 20, 2024

I don't understand how this change would help. All it does is move the new into a helper function.

Have you been able to track down the retention root for the instances that you see increasing? This is purely managed code so you're probably not really seeing a leak you're seeing unexpected retention.

@DavoudEshtehari DavoudEshtehari linked an issue Mar 26, 2024 that may be closed by this pull request
@DavoudEshtehari DavoudEshtehari added the 💡 Enhancement New feature request label Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💡 Enhancement New feature request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Memory Leak SqlConnectionFactory
4 participants