How to delete an object which is used as part of an instance definition

I create an instanceDefintion for get a image from InstanceDefinition to show.
then, I want to delete all objects in this process, but i can not delete or purge these objects.
the code like below:

List<GeometryBase> geometries = new List<GeometryBase>
int idefindex = doc.InstanceDefinitions.Add("preview", string.Empty, Point3d.Origin, geometries);

// get image
var previewBitmap = doc.InstanceDefinitions[idefindex].CreatePreviewBitmap(DefinedViewportProjection.Perspective, doc.DisplayMode.Default, new System.Drawing.Size(320, 200):

// now doc.Object's Count is 3 and rhino_objects.Length is 3 too
var rhino_objects = doc.InstanceDefinitions[idefindex].GetObjects();

// delete InstanceDefinition
doc.InstanceDefinition.Delete(idefindex, true, true);

//then purge these object  in rhinoobject[], thes objects is part of instanceDefiniton
for (int i =0; i < rhino_objects.Length; i++)
       doc.Objects.Delete(rhino_objects[i], true, true);

// doc.Object's Count is 3 still.
//  Check the rhinoobjects[0], object's IsNormal= false, isLock=fasle , isHidden=false 

I want to know how to purge these objects?

Thank you.

Hi @ddseven_2000,

There is no reason to purge the instance definition geometry. InstanceDefinitionTable.Delete will tag all instance definition geometry for deletion, meaning they won’t save to a .3dm. file.

– Dale

Hi, Dale Fugier:

Thank for your reply.
After InstanceDefinition.Table.Delete, it will not save to .3dm file. but in the RhinoDoc.ActiveDoc.Objects.Count don’t decrease. you can still find it in ObjectTable. I mean I want to purge they.