Page MenuHome

Memory leak if both a shader and an AddonPreferences class are used
Open, Confirmed, LowPublic

Description

System Information
Operating system: Windows-10-10.0.18362 64 Bits
Graphics card: GeForce RTX 2080/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 431.86

Blender Version
Broken: version: Official 2.80 (sub 75), branch: master, commit date: 2019-07-29 14:47, hash: rBf6cb5f54494e

Short description of error
Blender shows the warning Error: Not freed memory blocks: 4, total unfreed memory 0.012421 MB when an addon uses both AddonPreferences with an implementation of the draw() method and an instance of gpu.types.GPUShader.

Exact steps for others to reproduce the error

  • Install the following demo addon:
  • Start Blender from console with blender.exe --factory-startup --addons memleak
  • Exit Blender. It will print Error: Not freed memory blocks: 4, total unfreed memory 0.012421 MB.

If you open the addon in a text editor and comment out line 30 (shader = gpu.types.GPUShader(vertex_shader, fragment_shader)), the error is no longer shown.
Similarly, if you comment out lines 37 and 38 instead (def draw(self, context): pass) and leave line 30 enabled, the error will also not show up.
Of course this problem might also be caused by other conditions, but those two (shader and AddonPreferences class) are the combination where I spotted the problem first.

Details

Type
Bug

Event Timeline

Germano Cavalcante (mano-wii) lowered the priority of this task from Needs Triage by Developer to Confirmed, Low.Wed, Nov 6, 3:00 PM

Although it is not recommended to create and maintain a reference to an object type shader in the top level of a module (shaders are slow to create and use a lot of GPU resources),
the fact that an object of type AddonPreferences results in a memory leak indicates that somewhere in the creation of such object has a wrong refcount.

This is something that deserves investigation but really doesn't have much priority.

it is not recommended to create and maintain a reference to an object type shader in the top level of a module (shaders are slow to create and use a lot of GPU resources)

Why would that be a problem? This code is executed exactly once at Blender startup.
(This is a bit off-topic, but I would appreciate to learn more about this comment)