René's URL Explorer Experiment


Title: memory leak - simple function call in a loop · Issue #541 · pythonnet/pythonnet · GitHub

Open Graph Title: memory leak - simple function call in a loop · Issue #541 · pythonnet/pythonnet

X Title: memory leak - simple function call in a loop · Issue #541 · pythonnet/pythonnet

Description: I'm getting a memory leak with simple calls from .NET to Python function. The issue is reproducible on all pythonnet versions that I tested. When I test Python calls to .NET, then the memory leak is less obvious, since all resources are ...

Open Graph Description: I'm getting a memory leak with simple calls from .NET to Python function. The issue is reproducible on all pythonnet versions that I tested. When I test Python calls to .NET, then the memory leak i...

X Description: I'm getting a memory leak with simple calls from .NET to Python function. The issue is reproducible on all pythonnet versions that I tested. When I test Python calls to .NET, then the memory le...

Opengraph URL: https://github.com/pythonnet/pythonnet/issues/541

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"memory leak - simple function call in a loop","articleBody":"I'm getting a memory leak with simple calls from .NET to Python function. The issue is reproducible on all pythonnet versions that I tested. When I test Python calls to .NET, then the memory leak is less obvious, since all resources are released when calling the CPython `gc.collect()`. Calling the same function from .NET does not release any resources, but calling the CLR `GC.WaitForPendingFinalizers()` blocks the execution.\r\n\r\n[memoryleakpykw.zip](https://github.com/pythonnet/pythonnet/files/1293771/memoryleakpykw.zip)\r\n\r\n\r\n```python\r\n\u003e\u003e\u003e import clr\r\n\u003e\u003e\u003e import System\r\n\u003e\u003e\u003e for i in range(20000000):\r\n...   a=System.Double(i)\r\n...\r\n\u003e\u003e\u003e import gc\r\n\u003e\u003e\u003e gc.collect()\r\n```\r\n\r\n`pyinclr.py`\r\n```python\r\ndef testmethod():\r\n\treturn \"abc\"*3\r\n```\r\n\r\n```csharp\r\nusing System;\r\nusing Python.Runtime;\r\n\r\nnamespace memoryleakpykw\r\n{\r\n    class Program\r\n    {\r\n        static void Main(string[] args)\r\n        {\r\n            PyObject pymodule;\r\n            PyObject gc;\r\n            PyObject testmethod;\r\n\r\n            PythonEngine.Initialize();\r\n\r\n            IntPtr pylock = PythonEngine.AcquireLock();\r\n            {\r\n                PyObject sys = PythonEngine.ImportModule(\"sys\");// Py.Import(\"sys\");\r\n                gc = PythonEngine.ImportModule(\"gc\");// Py.Import(\"sys\");\r\n                sys.GetAttr(\"path\").InvokeMethod(\"append\",\r\n                    new PyString(@\"C:\\Users\\denis.akhiyarov\\source\\repos\\memoryleakpykw\\pyinclr\"));\r\n                pymodule = PythonEngine.ImportModule(\"pyinclr\");\r\n                testmethod = pymodule.GetAttr(\"testmethod\");\r\n            }\r\n\r\n            PythonEngine.ReleaseLock(pylock);\r\n\r\n            Console.WriteLine(\"starting test for memory leak, press any key\");\r\n            Console.ReadKey();\r\n\r\n            pylock = PythonEngine.AcquireLock();\r\n\r\n            {\r\n                for (int i=1; i\u003c=1000000; i++)\r\n                {\r\n                    testmethod.Invoke();\r\n                }\r\n            }\r\n\r\n            gc.InvokeMethod(\"collect\"); \r\n\r\n            PythonEngine.ReleaseLock(pylock);\r\n            \r\n            GC.Collect();\r\n            //GC.WaitForPendingFinalizers(); // this blocks execution\r\n            GC.Collect();\r\n\r\n            Console.WriteLine(\"finished test for memory leak, press any key\");\r\n            Console.ReadKey();\r\n        }\r\n\r\n    }\r\n}\r\n```\r\n\r\n\r\n\r\n\r\n","author":{"url":"https://github.com/den-run-ai","@type":"Person","name":"den-run-ai"},"datePublished":"2017-09-11T19:32:06.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":14},"url":"https://github.com/541/pythonnet/issues/541"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:c2e6a5e1-0813-f617-c5e6-cf06bef36b90
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idAD5A:11F8A0:48F7874:63208BF:69730550
html-safe-nonce4ef9f7d71d19c9e29f2e56a0e4a35e4eaf8215ecdefd7fa0c76eb4f4d6bd284f
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRDVBOjExRjhBMDo0OEY3ODc0OjYzMjA4QkY6Njk3MzA1NTAiLCJ2aXNpdG9yX2lkIjoiODczODY3NjAyNzMwMDkxODU2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac1999220fbdd00b31e2056b2378d9dbc39fa54dcf398bddd6fb56ae144e45bbb8
hovercard-subject-tagissue:256816591
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/pythonnet/pythonnet/541/issue_layout
twitter:imagehttps://opengraph.githubassets.com/681777193dac58b8549c716c8110fe7ec93e4a96cb0f8e750586b81186e27461/pythonnet/pythonnet/issues/541
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/681777193dac58b8549c716c8110fe7ec93e4a96cb0f8e750586b81186e27461/pythonnet/pythonnet/issues/541
og:image:altI'm getting a memory leak with simple calls from .NET to Python function. The issue is reproducible on all pythonnet versions that I tested. When I test Python calls to .NET, then the memory leak i...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameden-run-ai
hostnamegithub.com
expected-hostnamegithub.com
None44ab3188c1dcfe3be0f9c3feca2e04e14fb79f120939ce2395e4f15ab96ec1d4
turbo-cache-controlno-preview
go-importgithub.com/pythonnet/pythonnet git https://github.com/pythonnet/pythonnet.git
octolytics-dimension-user_id6050430
octolytics-dimension-user_loginpythonnet
octolytics-dimension-repository_id14748123
octolytics-dimension-repository_nwopythonnet/pythonnet
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id14748123
octolytics-dimension-repository_network_root_nwopythonnet/pythonnet
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasea5e2b48bd1260476599758f5d253b5d24092ab84
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/pythonnet/pythonnet/issues/541#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpythonnet%2Fpythonnet%2Fissues%2F541
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpythonnet%2Fpythonnet%2Fissues%2F541
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=pythonnet%2Fpythonnet
Reloadhttps://github.com/pythonnet/pythonnet/issues/541
Reloadhttps://github.com/pythonnet/pythonnet/issues/541
Reloadhttps://github.com/pythonnet/pythonnet/issues/541
pythonnet https://github.com/pythonnet
pythonnethttps://github.com/pythonnet/pythonnet
Notifications https://github.com/login?return_to=%2Fpythonnet%2Fpythonnet
Fork 769 https://github.com/login?return_to=%2Fpythonnet%2Fpythonnet
Star 5.4k https://github.com/login?return_to=%2Fpythonnet%2Fpythonnet
Code https://github.com/pythonnet/pythonnet
Issues 155 https://github.com/pythonnet/pythonnet/issues
Pull requests 18 https://github.com/pythonnet/pythonnet/pulls
Discussions https://github.com/pythonnet/pythonnet/discussions
Actions https://github.com/pythonnet/pythonnet/actions
Projects 0 https://github.com/pythonnet/pythonnet/projects
Wiki https://github.com/pythonnet/pythonnet/wiki
Security 0 https://github.com/pythonnet/pythonnet/security
Insights https://github.com/pythonnet/pythonnet/pulse
Code https://github.com/pythonnet/pythonnet
Issues https://github.com/pythonnet/pythonnet/issues
Pull requests https://github.com/pythonnet/pythonnet/pulls
Discussions https://github.com/pythonnet/pythonnet/discussions
Actions https://github.com/pythonnet/pythonnet/actions
Projects https://github.com/pythonnet/pythonnet/projects
Wiki https://github.com/pythonnet/pythonnet/wiki
Security https://github.com/pythonnet/pythonnet/security
Insights https://github.com/pythonnet/pythonnet/pulse
New issuehttps://github.com/login?return_to=https://github.com/pythonnet/pythonnet/issues/541
New issuehttps://github.com/login?return_to=https://github.com/pythonnet/pythonnet/issues/541
memory leak - simple function call in a loophttps://github.com/pythonnet/pythonnet/issues/541#top
bughttps://github.com/pythonnet/pythonnet/issues?q=state%3Aopen%20label%3A%22bug%22
https://github.com/den-run-ai
https://github.com/den-run-ai
den-run-aihttps://github.com/den-run-ai
on Sep 11, 2017https://github.com/pythonnet/pythonnet/issues/541#issue-256816591
memoryleakpykw.ziphttps://github.com/pythonnet/pythonnet/files/1293771/memoryleakpykw.zip
bughttps://github.com/pythonnet/pythonnet/issues?q=state%3Aopen%20label%3A%22bug%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.