public void OnDocumentRemoved() { // we need to call OnRemoveFromDocument on all children // NativeObjectAdapter.OnRemoveFromDocument is hierarchical, // so we only need to call on the top level children DomNode node = this.DomNode; if (node != null) { foreach (var subnode in node.Children) { NativeObjectAdapter childObject = subnode.As <NativeObjectAdapter>(); if (childObject != null) { childObject.OnRemoveFromDocument(this); } } } // destroy the document on the native side, as well var tag = node.Type.GetTag(NativeAnnotations.NativeDocumentType); var typeId = (tag != null) ? (uint)tag : 0; GameEngine.DeleteDocument(m_nativeDocId, typeId); }