13.12.2014 10:29, Claudio Valderrama C. пишет:
> 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).
You are correct, it was mine bug in latest change of this code (before
it there was no remove() call). There should to be
m_relations[pos] = NULL;
instead. The goal is to safely remove item from array before destroying it.
The code is a bit paranoid.
> Why not doing the loop in reverse order?
Because whole array is cleared after the loop ;)
Fixed.
Thanks,
Vlad
------------------------------------------------------------------------------
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