public void destroyClassReally(IClassObject classObject) { if (!isMainThread()) { logError("只能在主线程中使用ClassPool,子线程中请使用ClassPoolThread代替"); return; } bool inuse = isInuse(classObject); classObject.resetProperty(); classObject.setDestroy(true); // 从已使用列表中移除 if (inuse) { removeInuse(classObject); } // 从未使用列表中移除 else { if (mUnusedList.TryGetValue(classObject.GetType(), out HashSet <IClassObject> list) && list.Count > 0) { list.Remove(classObject); } } }
protected bool markUnused(IClassObject classObject, ref string info) { // 加入未使用列表 Type type = classObject.GetType(); if (!mUnusedList.ContainsKey(type)) { mUnusedList.Add(type, new List <IClassObject>()); } else { if (mUnusedList[type].Contains(classObject)) { info = "ClassObject is in Unused list! can not add again!"; return(false); } } mUnusedList[type].Add(classObject); // 从使用列表移除,要确保操作的都是从本类创建的实例 if (!mInusedList.ContainsKey(type)) { info = "can not find class type in Inused List! type : " + type; return(false); } if (!mInusedList[type].Remove(classObject)) { info = "Inused List not contains class object!"; return(false); } return(true); }
protected void removeInuse(IClassObject classObject) { // 从使用列表移除,要确保操作的都是从本类创建的实例 Type type = classObject.GetType(); if (!mInusedList.ContainsKey(type)) { logError("can not find class type in Inused List! type : " + type); } if (!mInusedList[type].Remove(classObject)) { logError("Inused List not contains class object!"); } }
//---------------------------------------------------------------------------------------------------------------------------------------------- protected void addInuse(IClassObject classObject) { Type type = classObject.GetType(); if (!mInusedList.ContainsKey(type)) { mInusedList.Add(type, new List <IClassObject>()); } else { if (mInusedList[type].Contains(classObject)) { logError("object is in inused list"); return; } } // 加入使用列表 mInusedList[type].Add(classObject); }
protected void addUnuse(IClassObject classObject) { // 加入未使用列表 Type type = classObject.GetType(); if (!mUnusedList.ContainsKey(type)) { mUnusedList.Add(type, new Stack <IClassObject>()); } else { if (mUnusedList[type].Contains(classObject)) { logError("ClassObject is in Unused list! can not add again!"); return; } } mUnusedList[type].Push(classObject); }
protected bool markUsed(IClassObject classObject) { Type type = classObject.GetType(); if (!mInusedList.ContainsKey(type)) { mInusedList.Add(type, new List <IClassObject>()); } else { if (mInusedList[type].Contains(classObject)) { return(false); } } // 加入使用列表 mInusedList[type].Add(classObject); // 从未使用列表移除 if (mUnusedList.ContainsKey(type)) { mUnusedList[type].Remove(classObject); } return(true); }
//---------------------------------------------------------------------------------------------------------------------------------------------- protected bool checkUsed(IClassObject classObject) { Type type = classObject.GetType(); return(mInusedList.ContainsKey(type) && mInusedList[type].Contains(classObject)); }