Skip to content

OpenSim::Set::insert() can cause issues with MATLAB garbage collector #3274

@carmichaelong

Description

@carmichaelong

This was seen when @gurchiek was using MATLAB to insert a new point into a PathPointSet created with clone().

clone() creates a new point that did not have a model or owner (hasModel() and hasOwner() were false). Then, using PathPointSet::insert() and finalizeConnections() made the Set take ownership, which can cause problems with MATLAB's garbage collector. Using markAdopted() fixed the issue in an isolated example.

We should consider adding this to one of our .i files (perhaps java_simulation.i?). Some things to note:

  1. If the object being inserted is non-const, we still might need to check if the Set has getMemoryOwner() as true or false. https://simtk.org/api_docs/opensim/api_docs/classOpenSim_1_1Set.html#adf1da111571bb1f156da8ab169181a48
  2. If the object being inserted is const, we wouldn't need to check as it always makes a copy, but I'm not sure how/if MATLAB differentiates between these two methods anyway. https://simtk.org/api_docs/opensim/api_docs/classOpenSim_1_1Set.html#af79a11b57529978ce78c9dc28771bfe2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions