Skip to content

Memory leak in function matplotlib._path.affine_transform #20641

Closed

Description

@Stardust1225

Bug report

When I input an illegal value into the function matplotlib._path.affine_transform, the memory use is increasing as the number of calls.

Code for reproduction

import sys
import tracemalloc
import numpy
import matplotlib._path

arg_list = []
arg_list.append(True)
arg_list.append(True)
arg_list.append(False)
arg_list.append(False)
arg_list.append(False)
arg_list.append(False)
arg_list.append(False)
arg_list.append(False)
arg_list.append(False)

memory_recorder = []
tracemalloc.start()
start_snapshot = tracemalloc.take_snapshot()
for i in range(0, 100):
  try:
    matplotlib._path.affine_transform([], numpy.array(
      [[arg_list[0], arg_list[1], arg_list[2]], [arg_list[3], arg_list[4], arg_list[5]],
       [arg_list[6], arg_list[7], arg_list[8]]]))
  except:
    pass
  if i % 10 == 0:
    one_snapshot = tracemalloc.take_snapshot()
    memory_recorder.append(one_snapshot.compare_to(start_snapshot, 'lineno')[0])

for i in range(2, len(memory_recorder)):
  print(memory_recorder[i].traceback)
  print(memory_recorder[i].size)

tracemalloc.stop()

Actual outcome

test.py:22
2497
test.py:22
3617
test.py:22
4737
test.py:22
5809
test.py:22
6977
test.py:22
8049
test.py:22
9217
test.py:22
10337

As the output shows, the memory use of line 22 is increasing as the number of calls increases.

I install matplotlib from source code via command pip3 install -e .
and the version is commit 9e0bb9c

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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