People, can someone explain how does this work? Probably it's obvious but I couldn't find the answer myself.
GarbageCollector::~GarbageCollector() { SyncLockGuard exGuard(&m_sync, SYNC_EXCLUSIVE, "GarbageCollector::~GarbageCollector"); for (FB_SIZE_T pos = 0; pos < m_relations.getCount(); pos++) { RelationData* relData = m_relations[pos]; Sync sync(&relData->m_sync, "GarbageCollector::~GarbageCollector"); sync.lock(SYNC_EXCLUSIVE); m_relations.remove(pos); sync.unlock(); delete relData; } m_relations.clear(); } For what I see, m_relations.remove(pos) is called inside the loop. Being m_relations a specialized SortedArray, it inherits a remove() method that shifts the trailing elements one position lower and decrements the count of elements. If this is happening already, then this logic doesn't work: for (FB_SIZE_T pos = 0; pos < m_relations.getCount(); pos++) m_relations.remove(pos); because it's deleting every other element (then it's missing half the elements). Why not doing the loop in reverse order? It's faster than forcing an element shift for each relation: for (FB_SIZE_T pos = m_relations.getCount(); pos > 0; --pos) { RelationData* relData = m_relations[pos - 1]; .... m_relations.remove(pos - 1); } Thanks and I would be happy to be told that the current code is correct and I didn't take something obvious into account. C. --- Claudio Valderrama C. Consultant, SW developer. ------------------------------------------------------------------------------ Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server from Actuate! Instantly Supercharge Your Business Reports and Dashboards with Interactivity, Sharing, Native Excel Exports, App Integration & more Get technology previously reserved for billion-dollar corporations, FREE http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk Firebird-Devel mailing list, web interface at https://lists.sourceforge.net/lists/listinfo/firebird-devel