void GarbageCollector::RemoveReferencesToNode( wxNode* pItemNode ) { wxNode* pNode = mAllNodes.GetFirst(); while( pNode ) { wxList& refLst = node_to_item( pNode ).mRefs; wxNode* pRefNode = refLst.GetFirst(); while( pRefNode ) { if ( pRefNode->GetData() == (wxObject*)pItemNode ) { wxNode* pNext = pRefNode->GetNext(); refLst.DeleteNode( pRefNode ); pRefNode = pNext; continue; } else pRefNode = pRefNode->GetNext(); } pNode = pNode->GetNext(); } }
void GarbageCollector::DestroyItemList( wxList& lst ) { wxNode* pNode = lst.GetFirst(); while( pNode ) { delete &node_to_item( pNode ); pNode = pNode->GetNext(); } lst.Clear(); }
wxNode* GarbageCollector::FindReferenceFreeItemNode() { wxNode* pNode = mAllNodes.GetFirst(); while( pNode ) { if ( node_to_item( pNode ).mRefs.GetCount() == 0 ) return pNode; pNode = pNode->GetNext(); } return 0; }
wxNode* GarbageCollector::FindItemNode( void* pForObj ) { wxNode* pNode = mAllNodes.GetFirst(); while( pNode ) { if ( node_to_item( pNode ).mpObj == pForObj ) return pNode; pNode = pNode->GetNext(); } return NULL; }
//删除节点,释放节点空间 int student_del(struct listnode *list,int id) { struct listnode *node; student *stu; list_for_each(node,list){ stu = node_to_item(node,student,_list); if(id == stu->id){ printf("list_del, id:%d,name:%s\n",stu->id,stu->name); list_remove(node); #ifdef STUDENT_FREE_MEMORY //释放节点空间 free(stu); stu = NULL; #endif return 1; } }
void GarbageCollector::ResolveReferences() { wxNode* pNode = mAllNodes.GetFirst(); while( pNode ) { GCItem& item = node_to_item( pNode ); wxNode* pRefNode = item.mRefs.GetFirst(); while( pRefNode ) { pRefNode->SetData( (wxObject*) FindItemNode( (void*)pRefNode->GetData() ) ); pRefNode = pRefNode->GetNext(); } pNode = pNode->GetNext(); } }
void GarbageCollector::AddDependency( void* pObj, void* pDependsOnObj ) { node_to_item( FindItemNode( pObj ) ).mRefs.Append( (wxObject*)pDependsOnObj ); }