[Maya, C++] Proper way to remove objects from scene?

I’m trying to remove a imported scene but MFileIO::unloadReference() is not what I’m looking for (It can’t find the file once in the scene) so I am trying to do it manually by deleting the mesh and joints with the namespace “Imported”:

int Helper::UnloadScene()
{
  MStatus status; 

  MObjectArray objs = MNamespace::getNamespaceObjects("Imported", false, &status);
  for (unsigned int i = 0; i < objs.length(); i++)
  {
    MFn::Type fn = objs[i].apiType();
    if (fn == MFn::kMesh || fn == MFn::kJoint)
      MGlobal::deleteNode(objs[i]);
  }
  return status;
}

But this still leaves behind dag objects in the scene:

Since I am only removing the mesh and joints, does anyone have a cleaner way of removing (the entire) imported scene? The reason I am doing this is I am batching out copying skin weights and my solution is to just add a scene to a existing weighted scene then binding and copying weights then saving that out.

What is the error you are seeing with unloadReference? Have you tried using MFileIO::getReferences()?