protected override void OnSave(InterDomainContext context)
{
base.OnSave(context);
System.Diagnostics.Debug.Assert(dict == GetObjectDict(pyHandle));
foreach (var attr in cache.Values)
{
Runtime.XIncref(attr.pyHandle);
}
// Decref twice in tp_clear, equilibrate them.
Runtime.XIncref(dict);
Runtime.XIncref(dict);
// destroy the cache(s)
foreach (var pair in cache)
{
if ((Runtime.PyDict_DelItemString(DictRef, pair.Key) == -1) &&
(Exceptions.ExceptionMatches(Exceptions.KeyError)))
{
// Trying to remove a key that's not in the dictionary
// raises an error. We don't care about it.
Runtime.PyErr_Clear();
}
else if (Exceptions.ErrorOccurred())
{
throw new PythonException();
}
pair.Value.DecrRefCount();
}
cache.Clear();
}