Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Deleted dotnet object does not get garbage collected #1872

Closed
@m-rossi

Description

@m-rossi

Environment

  • Pythonnet version: 3.0.0rc3
  • Python version: 3.10.5
  • Operating System: Windows 10 20H2
  • .NET Runtime: 6.0.6

Details

  • Describe what you were trying to get done.

Create dotnet-object and delete it. If I do that a lot I get memory issues. It seems the never get cleared by the Python- or dotnet-gc. This is not a problem in pythonnet 2.5.2

  • What commands did you run to trigger this issue?
importgcimportclrimportpsutilimportmatplotlib.pyplotaspltimportSystem# Create dict store count of objects lefttypes= [str,System.String,]types= {obj:0forobjintypes}N=1_000str_size=1_000_000memory_py= [0for_inrange(N+2)]memory_py[0]=psutil.virtual_memory().usedforiiinrange(N):s_py=str('a'*str_size)dels_pymemory_py[ii+1]=psutil.virtual_memory().used-memory_py[0]gc.collect()# See what types of objects are still presentforobjingc.get_objects():iftype(obj)inlist(types.keys()):types[type(obj)]+=1print(types)memory_py[ii+2]=psutil.virtual_memory().used-memory_py[0]memory_py[0]=0
{<class 'str'>: 0, <class 'System.String'>: 0}
memory_net= [0for_inrange(N+2)]memory_net[0]=psutil.virtual_memory().useds_py=str('a'*str_size)foriiinrange(N):s_net=System.String(s_py)dels_netmemory_net[ii+1]=psutil.virtual_memory().used-memory_net[0]gc.collect()# See what types of objects are still presentforobjingc.get_objects():iftype(obj)inlist(types.keys()):types[type(obj)]+=1print(types)memory_net[ii+2]=psutil.virtual_memory().used-memory_net[0]memory_net[0]=0
{<class 'str'>: 0, <class 'System.String'>: 1000}

You can also visualize the memory consumption:

fig,ax=plt.subplots()ax.plot(memory_py,label='Python object')ax.plot(memory_net,label='DotNet object')ax.legend()plt.show(fig)

3 0

You can execute the same code with pythonnet 2.5.2 (Python 3.9.13) and get the following figure

2 5

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp