RhinoInside python script terminal error when read and write

Hello forum members,
When I run the script, I am getting an this error. It is especially when I read the 3dm file, I came across this error.

C:\Users\fited\Desktop\python-rhino-script>python -m rhinoInsideTest2

Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at UnsafeNativeMethods.CRhinoDoc_Delete(UInt32 serialNumber)
   at Rhino.RhinoDoc.Finalize()

my script is

mport rhinoinside
rhinoinside.load()
import Rhino
import os
import time

# input file path
inputFile = r'C:\Users\fited\Downloads\2021_06_07_Brace_Model.3dm'

# get the template file path
templateFile = Rhino.ApplicationSettings.FileSettings.TemplateFile
rhinoDoc = Rhino.RhinoDoc.CreateHeadless(templateFile)
Rhino.RhinoDoc.ActiveDoc = rhinoDoc
Rhino.Commands.CommandStyleAttribute(2)
rhinoDoc.Import(inputFile)
time.sleep(10)
Rhino.RhinoApp.RunScript('_-GrasshopperPlayer 2021_03_11_Brace_Generation_Script.gh',False)
time.sleep(5)
Rhino.RhinoApp.RunScript(' -exit N _-Enter',False)

Is there any suggestion for this problem?

Try calling rhinoDoc.Dispose() at the end of your script.

Thank you Steve. When I wrote the rhinoDoc.Dispose(), there was no error. But grasshopper plugin not worked. I used GetPlugInObject and OpenDocument with grasshopper file but grasshopper file did not applied on my 3dm file. What should I do?

pluginObject = Rhino.RhinoApp.GetPlugInObject("Grasshopper")