Page MenuHome

Python/BMesh: CDLayer access does not free memory
Open, Confirmed, MediumPublic

Description

System Information
Operating system: Windows-7-6.1.7601-SP1 64 Bits
Graphics card: AMD Radeon HD 7560D ATI Technologies Inc. 4.5.13399 Core Profile Context 15.200.1062.1004

Blender Version
Broken: version: 2.81 (sub 16), branch: master, commit date: 2019-10-27 13:40, hash: rB9b6aa740be31
Worked: (optional)

Short description of error
bmesh module does not free memory.

Exact steps for others to reproduce the error
Open the test_memory.blend file:

Run the script that is in the text editor.

Open the console. The following text will be written in the console:

C:\Users\Pavel\Desktop\test_memory.blend\test_mem.py:14: size=1476 KiB, count=31488, average=48 B

This means that the function did not free memory. I found out with the standard tracemalloc module

Details

Type
Bug

Event Timeline

This error occurs not only with Vertex Colors, but also with UV.

Philipp Oeser (lichtwerk) lowered the priority of this task from Needs Triage by Developer to Confirmed, Medium.Tue, Nov 5, 12:28 PM

Not really familiar with tracemalloc, looks like this would bemore reliable to trace leaks?
(Sorry if this boils down to the same...)

import tracemalloc

import bpy, bmesh


def test_memory():
    bpy_obj = bpy.context.object
    bm = bmesh.new()
    bm.from_mesh(bpy_obj.data)

    vertex_colors = bm.loops.layers.color['Col']
    for face in bm.faces:
        for loop in face.loops:
            vertex_color = loop[vertex_colors]

    del vertex_colors
    bm.clear()
    del bm


tracemalloc.start()

snapshot1 = tracemalloc.take_snapshot()
test_memory()
snapshot2 = tracemalloc.take_snapshot()

top_stats = snapshot2.compare_to(snapshot1, 'lineno')

print("[ Top 10 differences ]")
for stat in top_stats[:10]:
    print(stat)

I can confirm that we get something reported that seemingly looks like leaks.

CC @Campbell Barton (campbellbarton) : Can you confirm? Is this a known thing?
Also note that T67093: Python/BMesh: Crash on UV changes when handling depsgraph update - CDLayer re-allocation issue seems to be related

Philipp Oeser (lichtwerk) renamed this task from bmesh module does not free memory to Python/BMesh: CDLayer access does not free memory.Tue, Nov 5, 12:29 PM