Title: Memory Leak in python when using a C# DLL · Issue #577 · pythonnet/pythonnet · GitHub
Open Graph Title: Memory Leak in python when using a C# DLL · Issue #577 · pythonnet/pythonnet
X Title: Memory Leak in python when using a C# DLL · Issue #577 · pythonnet/pythonnet
Description: Environment Pythonnet version: 2.3.0 Python version: 3.6.1 Operating System: Windows 7 Professional 64bits. .NET Framework 4.6 Details I experience memory leaks when trying to use a C# dll in python to run a simulation and retrieve resul...
Open Graph Description: Environment Pythonnet version: 2.3.0 Python version: 3.6.1 Operating System: Windows 7 Professional 64bits. .NET Framework 4.6 Details I experience memory leaks when trying to use a C# dll in pytho...
X Description: Environment Pythonnet version: 2.3.0 Python version: 3.6.1 Operating System: Windows 7 Professional 64bits. .NET Framework 4.6 Details I experience memory leaks when trying to use a C# dll in pytho...
Opengraph URL: https://github.com/pythonnet/pythonnet/issues/577
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Memory Leak in python when using a C# DLL","articleBody":"### Environment\r\n\r\n- Pythonnet version: 2.3.0\r\n- Python version: 3.6.1\r\n- Operating System: Windows 7 Professional 64bits.\r\n- .NET Framework 4.6 \r\n\r\n### Details\r\n\r\n- I experience memory leaks when trying to use a C# dll in python to run a simulation and retrieve results using python. When I try to run multiple time the calculation I get leaks\r\nHere is a template of code I run to experience this memory leak (replaced the name of the dll I use by generic names)\r\n\r\n```python\r\nimport clr\r\nimport os\r\nimport sys\r\nimport psutil\r\nimport gc\r\ndll_path = r''the path to my dll\"\r\nsys.path.append(os.path.join(dll_path, 'MyDll.dll'))\r\nclr.AddReference(os.path.join(dll_path, \"MyDll\"))\r\nwhile psutil.virtual_memory().percent \u003c 80:\r\n print('psutil_virtual_memory:', psutil.virtual_memory().percent)\r\n obj = MyDll.MyObject()\r\n res = obj.Run() # long simulation is run and I get the results.\r\n gc.collect()\r\n clr.System.GC.Collect()\r\n```\r\nOutput : \r\n psutil_virtual_memory: 41.8\r\n psutil_virtual_memory: 44.4\r\n psutil_virtual_memory: 46.6\r\n psutil_virtual_memory: 48.9\r\n .....\r\n until my memory reach 80%\r\n\r\nThe issue is that running the equivalent code in C# does not give any memory leak but it's when calling it from python we get issues of memory leaks. the python garbage collector doesn't help at all with this. I tried also to call the System GC Collect but without success too.\r\n\r\nMy question is how can I investigate and try to fix this issue. \r\n\r\n\r\n","author":{"url":"https://github.com/BreitA","@type":"Person","name":"BreitA"},"datePublished":"2017-11-24T14:11:08.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":15},"url":"https://github.com/577/pythonnet/issues/577"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:9ed5ecb4-eeea-5f78-a532-a17d72e30eb6 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AF7C:38727B:A1813D:DFA178:69738AA9 |
| html-safe-nonce | 74bce371ab9fb8bd2b609cc95ce9f050d0a9a410ecc25385de89f8f883f2fced |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRjdDOjM4NzI3QjpBMTgxM0Q6REZBMTc4OjY5NzM4QUE5IiwidmlzaXRvcl9pZCI6IjMxNzM3MTI4NjE5MTM2NDc3ODUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | bf43a7f88bd60f79fe9fcf5cb491e12f25b04587d0cbf49311e5f31274beaf19 |
| hovercard-subject-tag | issue:276627905 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/pythonnet/pythonnet/577/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a87a833953dc2a9381f27308fc7a971c7d355e1af6b515bba68a30c76a9ad8fa/pythonnet/pythonnet/issues/577 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a87a833953dc2a9381f27308fc7a971c7d355e1af6b515bba68a30c76a9ad8fa/pythonnet/pythonnet/issues/577 |
| og:image:alt | Environment Pythonnet version: 2.3.0 Python version: 3.6.1 Operating System: Windows 7 Professional 64bits. .NET Framework 4.6 Details I experience memory leaks when trying to use a C# dll in pytho... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | BreitA |
| hostname | github.com |
| expected-hostname | github.com |
| None | f0b5e2d1da32de5a0b7bcfbc5ba007c93e8e63098fba29e1200efb674aa72e66 |
| turbo-cache-control | no-preview |
| go-import | github.com/pythonnet/pythonnet git https://github.com/pythonnet/pythonnet.git |
| octolytics-dimension-user_id | 6050430 |
| octolytics-dimension-user_login | pythonnet |
| octolytics-dimension-repository_id | 14748123 |
| octolytics-dimension-repository_nwo | pythonnet/pythonnet |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 14748123 |
| octolytics-dimension-repository_network_root_nwo | pythonnet/pythonnet |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | c96653671324f9b6d4c5f787435acf56a06087dd |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width