0
$\begingroup$

I'm writing a script that imports an FBX with an animation, and exports frames of the animation as OBJ files. However, I noticed that regardless of how I delete my objects, Blender's memory usage increases every time I run the script. I looked at the memory statistics and this is what I got:

total memory len: 299.712 MB
peak memory len: 301.169 MB
slop memory len: 11.298 MB
ITEMS TOTAL-MiB AVERAGE-KiB TYPE
1203 ( 146.366   124.588) Chunk buffer
45252 ( 145.037     3.282) Data from AC
1109 (   2.189     2.022) BLI_Mempool Chunk
4633 (   1.128     0.249) PropertyRNA
3151 (   0.601     0.195) StructRNA
 1 (   0.532   544.750) TaskScheduler task threads
3417 (   0.417     0.125) IDProperty array dup
2542 (   0.371     0.149) dupli_mapalloc
1987 (   0.349     0.180) keymap entry
1888 (   0.346     0.188) operatortype
2017 (   0.246     0.125) IDProperty group

I understand that "Chunk buffer" refers to the memory used by the Undo function, but what is "Data from AC"? This is the memory usage just after opening the file, and there are currently no objects in the scene.

EDIT: Here is my delete function:

def clearScene():  
for i in range(20):
    bpy.data.scenes['Scene'].layers[i] = True  
print("All layers selected")     
bpy.ops.object.select_all(action='SELECT')
print("All objects selected")

bpy.ops.object.delete(use_global=True)
print("All objects deleted")
bpy_data = [bpy.data.actions,
         bpy.data.armatures,
         bpy.data.brushes,
         bpy.data.cache_files,
         bpy.data.cameras,
         bpy.data.curves,
         bpy.data.fonts,
         bpy.data.grease_pencil,
         bpy.data.groups,
         bpy.data.images,
         bpy.data.lamps,
         bpy.data.lattices,
         bpy.data.libraries,
         bpy.data.linestyles,
         bpy.data.masks,
         bpy.data.materials,
         bpy.data.meshes,
         bpy.data.metaballs,
         bpy.data.movieclips,
         bpy.data.node_groups,
         bpy.data.objects,
         bpy.data.paint_curves,
         bpy.data.palettes,
         bpy.data.particles,
         bpy.data.rna_type,
         bpy.data.scenes,
         bpy.data.screens,
         bpy.data.shape_keys,
         bpy.data.sounds,
         bpy.data.speakers,
         bpy.data.texts,
         bpy.data.textures,
         bpy.data.worlds]

for bpy_data_iter in bpy_data:
    for data in bpy_data_iter:
        bpy_data_iter.remove(data)

I realized an error in my delete function, but now with these last three lines, I get an error saying the BlendData data type is not iterable. Is there a better way to remove all data?

$\endgroup$
3
  • $\begingroup$ A quick grep on source (readfile.c) and it appears to be action data. (bpy.data.actions) AR for armature etc. Are you removing actions? $\endgroup$
    – batFINGER
    May 28, 2018 at 15:29
  • $\begingroup$ Yes, as far as I can tell, I'm removing just about everything,I delete all objects using bpy.ops.objects.delete, and then I iterate through everything in bpy.data and use the remove() function (added to my original post) $\endgroup$
    – sdighe
    May 28, 2018 at 15:35
  • $\begingroup$ Link to readfile.c Have a look here for clearing data Wouldn't use bpy.ops.objects.delete removng from bpy.data.objects will do that. $\endgroup$
    – batFINGER
    May 28, 2018 at 15:46

1 Answer 1

1
$\begingroup$

Okay, figured it out. Thanks to batFINGER for the link to readfile.c

I thought I was deleting actions, but it turns out a few things in bpy_data shouldn't have been in there, and were causing errors that led to Actions NOT being deleted. Once I cut the bpy_data list down to what it is below, everything deleted properly and I am now left with about 10M of memory usage. Here is the working delete function:

def clearScene():  
   for i in range(20):
       bpy.data.scenes['Scene'].layers[i] = True  
   print("All layers selected")     
   bpy.ops.object.select_all(action='SELECT')
   print("All objects selected")
   bpy_data = [bpy.data.actions,
         bpy.data.armatures,
         bpy.data.brushes,
         bpy.data.cameras,
         bpy.data.materials,
         bpy.data.meshes,
         bpy.data.objects,
         bpy.data.shape_keys,
         bpy.data.textures]

   for bpy_data_iter in bpy_data:
      for data in bpy_data_iter:
          bpy_data_iter.remove(data)

   bpy.ops.wm.save_mainfile()
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .