-
Notifications
You must be signed in to change notification settings - Fork 747
Memory Leak in python when using a C# DLL #577
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
Comments
Please try out the fix according to this issue: |
@denfromufa
My issue is that gc.collect() from python doesn't release my memory. I saw that you have a branch fixing the memory issue. Should I try to install the pythonnet version of your branch? |
Yes, try this branch developed by @dmitriyse: |
I also created branch https://github.com/pythonnet/pythonnet/tree/featured |
got this warning and this error when doing python setup.py bdist_wheel with your branch. Is there any quick fix I can try? |
Which .NET runtimes and VS versions do you have installed?
Can you try passing the `--xplat` option to the build?
…On Fri, Nov 24, 2017, 4:12 PM BreitA ***@***.***> wrote:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets(983,5): warning MSB3644: The reference assembl
ies for framework ".NETFramework,Version=v4.0" were not found. To resolve this, install the SDK or Targeting Pack for t
his framework version or retarget your application to a version of the framework for which you have the SDK or Targetin
g Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place
of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend.
CSC : error CS1617: Invalid option '6' for /langversion; must be ISO-1, ISO-2, 3, 4, 5 or Default
got this warning and this error when doing python setup.py bdist_wheel
with your branch. Is there any quick fix I can try?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#577 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHgZ5bTScu2DZmAOp3IBGABZoUMgrzP-ks5s5z9jgaJpZM4Qp3jn>
.
|
Also try building with more verbose mode in setup.py (set VERBOSITY flag)
On Fri, Nov 24, 2017, 10:36 PM Denis Akhiyarov <denis.akhiyarov@gmail.com>
wrote:
… Which .NET runtimes and VS versions do you have installed?
Can you try passing the `--xplat` option to the build?
On Fri, Nov 24, 2017, 4:12 PM BreitA ***@***.***> wrote:
> C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets(983,5): warning MSB3644: The reference assembl
> ies for framework ".NETFramework,Version=v4.0" were not found. To resolve this, install the SDK or Targeting Pack for t
> his framework version or retarget your application to a version of the framework for which you have the SDK or Targetin
> g Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place
> of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend.
>
> CSC : error CS1617: Invalid option '6' for /langversion; must be ISO-1, ISO-2, 3, 4, 5 or Default
>
> got this warning and this error when doing python setup.py bdist_wheel
> with your branch. Is there any quick fix I can try?
>
> —
> You are receiving this because you were mentioned.
>
>
> Reply to this email directly, view it on GitHub
> <#577 (comment)>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AHgZ5bTScu2DZmAOp3IBGABZoUMgrzP-ks5s5z9jgaJpZM4Qp3jn>
> .
>
|
Or just grab the binary wheels from the builds for this branch in appveyor
artifacts
On Fri, Nov 24, 2017, 10:41 PM Denis Akhiyarov <denis.akhiyarov@gmail.com>
wrote:
… Also try building with more verbose mode in setup.py (set VERBOSITY flag)
On Fri, Nov 24, 2017, 10:36 PM Denis Akhiyarov ***@***.***>
wrote:
> Which .NET runtimes and VS versions do you have installed?
>
> Can you try passing the `--xplat` option to the build?
>
> On Fri, Nov 24, 2017, 4:12 PM BreitA ***@***.***> wrote:
>
>> C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets(983,5): warning MSB3644: The reference assembl
>> ies for framework ".NETFramework,Version=v4.0" were not found. To resolve this, install the SDK or Targeting Pack for t
>> his framework version or retarget your application to a version of the framework for which you have the SDK or Targetin
>> g Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place
>> of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend.
>>
>> CSC : error CS1617: Invalid option '6' for /langversion; must be ISO-1, ISO-2, 3, 4, 5 or Default
>>
>> got this warning and this error when doing python setup.py bdist_wheel
>> with your branch. Is there any quick fix I can try?
>>
>> —
>> You are receiving this because you were mentioned.
>>
>>
>> Reply to this email directly, view it on GitHub
>> <#577 (comment)>,
>> or mute the thread
>> <https://github.com/notifications/unsubscribe-auth/AHgZ5bTScu2DZmAOp3IBGABZoUMgrzP-ks5s5z9jgaJpZM4Qp3jn>
>> .
>>
>
|
Sorry I didn't restarted my computer after installing VS I must be tired. So now I fixed this issue I got the following error
I added to path the winsdk link to this exe but this change nothing. I am on my home machine so the operating system is now : Installed Version: Community when using --xplat option ihave the same error about ildasm.exe after it runs through .NET core I have 3 ildasm.exe : it looks like this I checked the file in question and it seems it already calls the 1.2.7 of unmanagedexports |
I manage to install it from the following binary : https://ci.appveyor.com/project/pythonnet/pythonnet/branch/featured/job/7daumkda8h36k89t/artifacts this branch didn't fix my memory leak |
You need to provide minimum reproducible example like I did in the linked issue above. |
Ok I'll try to do that but it make take a while for me to identify one leaking element of the C# code library I use because I know very few thing about this code yet or about C# in general to begin with and this code is a simulator using multiple nested structure of C# objects. Anyway your simple example of instancing a double in a for loop doesn't cause memory leak in my case even on the release 2.3.0 version of pythonnet. I will try to instanciate a simple example of a nested structure of C# object to see if it leaks. I also used a temporary solution to work with until i fix the issue, I encapsulate my call to the C# library in a multiprocessing.Process. using multiprocessing.Pool, the memory leak is shared to the pool meaning if you have a lot of elements in your pool the memory leak will skyrocket pretty fast but when the whole pool end the memory leak is also cleaned Thanks for your time. |
You can also use .NET memory profiler such as one of these, but it may not work due to some unmanaged memory: https://stackoverflow.com/a/100490/2230844 The easiest is commenting out code until the leak is narrowed down to few lines of code. |
closing due to inactivity and no reproducible example |
@denfromufa Since i didn't have access to the C# code i couldn't do what was suggested. Anyway i circumvent the issue migrating my code to linux with mono and dont have memory leak issues there. |
Environment
Details
Here is a template of code I run to experience this memory leak (replaced the name of the dll I use by generic names)
Output :
psutil_virtual_memory: 41.8
psutil_virtual_memory: 44.4
psutil_virtual_memory: 46.6
psutil_virtual_memory: 48.9
.....
until my memory reach 80%
The 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.
My question is how can I investigate and try to fix this issue.
The text was updated successfully, but these errors were encountered: