[Bf-python] Got independent copy of mesh, now how to free it later?

Ken Hughes khughes at pacific.edu
Thu May 28 15:49:44 CEST 2009


lynx.abraxas at freenet.de wrote:
> On 25/05/09 20:58:13, Ken Hughes wrote:
>   
>> We added a "hack" for exporter so that if you create a mesh but don't
>> link it to an object (so that when Python deallocates the object, its
>> user count is 0) then the mesh data is freed.  See:
>>
>> http://www.blender.org/documentation/248PythonDoc/Mesh-module.html#New
>>     
>
> Hm, It says:
> Note:   if  the mesh is not linked to an object, its datablock will be deleted
> when the object is deallocated.
>
> How can python know to free the mesh when I deallocat an object if the mesh is
> not linked to the object?
> Is ob.unlink() ment by deallocation or is that done differently again?
>   

There is a field within the BPython Mesh object which is set True we you 
create a mesh using Blender.Mesh.New() (it should do the same when you 
call bpy.data.meshes.new() but apparently doesn't; that looks like a 
bug). The BPython Mesh_dealloc function checks this field and the 
Blender datablock's id.us values; if the field is True and id.us is 0, 
then it calls Blender's internal.

Ken




More information about the Bf-python mailing list