memory problems with apply subdivide tool

Issue #2091 resolved
jo do created an issue

hello

There a memory leak problem with the apply subdivide tool.

I have 32g ram and doing subv 2 with 600 morphs eat all my mem and crash when nothing left, don’t think it’s blender issue bcz doing the same task with smokejohn/SKkeeper on the same figure(g8) it's stable around 9-10GB ram and works great

I’m using blender 3.6 and latest import_daz version

thanks

Comments (13)

  1. Thomas Larsson repo owner

    The Apply Subsurf tool is written entirely in python, so there cannot be memory leaks. Unless it happens in calls to the Blender api, and in that case it is a Blender issue.

    However, it is a very expensive operation:

    1. Store all shapekey coordinates.
    2. Remove all shapekeys.
    3. Duplicate the mesh and apply the subdiv modifier.
    4. For each shapekey:

      1. Duplicate the original mesh again to a temporary mesh.
      2. Move vertices to the shapekey coordinates.
      3. Apply the subdiv modifier.
      4. Make a new shapekey for the subdivided mesh, and copy the locations from the temporary mesh.
      5. Delete the temporary mesh.

  2. Alessandro Padovani

    @jodo Keep in mind that in blender each shapekey stores the whole mesh, this is cumbersome especially for HD if you want to apply the modifiers. One way is to split the mesh if possible, for example separate the head from the body for the head shapekeys.

    @Thomas The addon by Johannes Rauch is a single source relatively short and well written, you may want to give it a look to see how he does things to save memory. This may be useful in general to optimize diffeomorphic in various areas, eventually.

    Let us know if you’re interested or we can close as invalid or wontfix since this is not a bug.

    https://github.com/smokejohn/SKkeeper/releases/tag/v1.6

  3. Domiek

    I have 128gb ram and do not experience a crash, but can confirm that there is some performance issues which seem related to the operation. I must restart blender after the apply subdiv/multires operation is complete. Blender performs very poorly unless restarted.

  4. Alessandro Padovani

    As an alternative, if Thomas is not interested, we can use the addon by Johannes instead.

  5. Thomas Larsson repo owner

    I had a look at Johannes' plugin, and agree that his way of doing it should be much faster. Will look at this when I have access to Blender tomorrow.

  6. Thomas Larsson repo owner

    I implemented what is essentially Johannes' code, and indeed it is faster. There should be better memory handling also in other parts of the plugin. There is a single place where objects are deleted, but the corresponding data blocks were left in memory. Now the data block is also deleted, provided that it has a single user.

  7. Alessandro Padovani

    Commit 62e45d4.

    I tested a level 2 multires with facs. The old version takes more and more memory as the process goes on, it’s more than 5 gb, I had to kill the process. The new commit stabilizes around 1.5 gb and takes around 6 minutes. So this is a tremendous improvement, thank you Thomas for your work on this.

    If there’s nothing to add we can close as resolved.

    p.s. For slow processes as this one, it would be useful to add a abort button if possible, otherwise the only way is to kill blender.

  8. Thomas Larsson repo owner

    Now the bvh retargeter also uses the new code to delete objects, which also deletes the object data for single users.

  9. Thomas Larsson repo owner

    I reused the code for a tool that applies arbitrary modifiers to a mesh with shapekeys. It is in the corrections panel. it is useful in the following situation. Let’s say that we have a nude figure with shapekeys in rest pose, and the same figure with clothes and posed (e.g. high heels).

    1. Copy pose from dressed to nude.
    2. Select the armature modifier and apply active modifier.
    3. Change armature for the clothes.

    Previously, the second step consisted to two substeps:

    2a. Apply rest pose.

    2b. Apply active shapekey.

    and 2b was veery slow.

  10. Log in to comment