[Bf-python] Problem with memory...

Joseph Eagar joeeagar at prodigy.net
Sun Jul 17 06:01:58 CEST 2005


Manuel wrote:

>
>
> I'w writing a tool to make hairs in Blender:
>
> http://www.dedalo-3d.com/public/forum/index.php?a=topic&topic=1121030552_19&page=1 
>
>
>
> During the usage, maybe the user want delete the hairs created
> (a sort of undo).
>
> To do this, I've written a simple function:
>
> def deleteHairs():
>     global objHairs
>     sc = Scene.getCurrent()
>     for ob in objHairs:
>         ob.getData().verts=[]
>         ob.getData().faces=[]
>    sc.unlink(ob)
>    sc.update(0)
>    objHairs = []
>
> where objHairs is a list of objs.
>
> The problem is: after this function the memory is not free...
> it remain exactly as when all objs exist.
>
> Suggestions? Maybe Blender undo?

There's a few problems with your code, actually. . .

First, you're making a NMesh wrapper twice, and not updating it (NMesh 
is a "intermediary" or "thick" wrapper, changes to it don't affect the 
mesh unless you call .update()).  Every time you call .getData(), a new 
NMesh is created, and unless you already called .update(), all changed 
you made will be lost.

 From a memory standpoint, clearing the meshes before un-linking the 
objects seems like a good idea, as Blender's "garbage collector" won't 
free the actual mesh unless you save and re-load the file, as Blender's 
"garbage collector" works by simply not saving unused data blocks.  I 
believe this was meant to act as a sort of undo system, where even 
deleted data blocks could be retrieved so long as the file was open. 

joeedh




More information about the Bf-python mailing list