UI panel checkbox memory leak

Hi,

Perhaps one of the Blender scripting experts might be able to help me with this.

The following code is causing a weird memory leak and I’m not sure why. The code creates a panel with a single checkbox in the ‘3D View’ tool shelf (the shelf to the right of the viewport). Whenever the checkbox in the panel is toggled Blender’s memory count increases alarmingly. Any idea why this is happening?

import bpy




class HelloWorldPanel(bpy.types.Panel):
    """Creates a Panel in the View3D UI panel"""
    bl_label = "Mesh Stats"
    bl_idname = "MESHSTATS_PT_hello"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'UI'
    
    def draw(self, context):
        layout = self.layout
        row = layout.row()
    
        my_settings = context.scene.my_settings
        row.prop(my_settings["my_bool"], "value")
        


class SceneSettingItem(bpy.types.PropertyGroup):
    name = bpy.props.StringProperty(name="Test Prop", default="Unknown")
    value = bpy.props.BoolProperty(name="Test Prop", default=False)




def register():
    bpy.utils.register_class(SceneSettingItem)


    bpy.types.Scene.my_settings = bpy.props.CollectionProperty(type=SceneSettingItem)


    my_item = bpy.context.scene.my_settings.add()
    my_item.name = "my_bool"
    my_item.value = False
    
    bpy.utils.register_class(HelloWorldPanel)


def unregister():
    bpy.utils.unregister_class(HelloWorldPanel)


if __name__ == "__main__":
    register()

Hm, you add an ID property to a panel, but it is actually a bpy.props property. Still, you should actually use template_list() for the collection, not one of its items.

You also add an item to the collection in register(), which is a big no-no. Also see http://wiki.blender.org/index.php/Extensions:2.6/Py/API_Changes#Restricted_Context

Thanks for the tips. The memory allocation apparently has something to do with the undo stack and is expected behaviour. It stops allocating once it reaches a certain amount.