std::vector< P_ITEM >::iterator it = toDelete.begin(); while( it != toDelete.end() ) { Items->DeleItem( (*it) ); it++; }
void gcollect () // Remove items which were in deleted containers{	int removed = 0, rtotal = 0;	bool bdelete;	LogMessage( "Performing Garbage Collection..." );	AllItemsIterator iter_items;		for( iter_items.Begin(); !iter_items.atEnd(); iter_items.Next() )	{		P_ITEM pi = iter_items.GetData();		if( pi->free || pi->isInWorld() )			continue;		bdelete = true;		// find the container if theres one.		if (isCharSerial(pi->contserial))		{			P_CHAR pc = FindCharBySerial( pi->contserial );			if (pc != NULL)				bdelete = false;		}		else		{			P_ITEM pContainer = GetOutmostCont(pi);			if (pContainer != NULL)				bdelete = false;		}		if (bdelete)		{			bool atBegin = false;			/*if( !iter_items.atBegin() )				--iter_items; // Go back for a little.			else				atBegin = true;*/			Items->DeleItem( pi ); // Warning, iterator became invalid!											   			/*if( atBegin )				iter_items.Begin();*/			//iter_items.First();			removed++;		}	}	rtotal += removed;		sprintf((char*)temp, " gc: Removed %i items", rtotal);	if (rtotal > 0) LogMessage((char*)temp);}