On Tue, 09 Jun 2009, Mindaugas Kavaliauskas wrote: Hi,
> I have a question/problem/discussion about garbage collection for chance > made of collectible pointer. > The code below prints: > ------------------------ > Test1 > oB is NIL > bbb destructor > After GC > Test2 > oB is NIL > After GC > aaa destructor > ------------------------ > How can we fix it? I see the only solution: collectible pointers should > have not only Destroy method, but also Mark. This is something like a > little move toward method support for collectible pointers. Yes it is. In the past Ryszard added support for registering mark/sweep functions (see hb_gcRegisterSweep() and hb_gcUnregisterSweep()) but it's hard to use them to resolve the problem like in your example due to reverted mark precedence. For this we need some more general solution. The easiest way is adding mark sweep function though probably it will be good to join this modification with some other. F.e. we should clearly define the GC API and introduce weak references as obligatory for each newly allocated block. To not increase allocated memory for HB_GARBAGE structure we can make it using the same trick as for extended references and register in current pFunc member pointer to static const structure with different functions. Now 'free' and 'mark'. If we want to keep backward compatibility then we can add new GC function and use 1 bit in flags to mark GC blocks with such function table instead of pure destructor function. And of course we will have to add function to mark pure GC blocks and document hb_gcUnlock() behavior for grip blocks. Alternatively we can introduce chains of references which can be bound with each GC block and add function to register/unregister such references. Registration grip block in references of some other GC block should automatically unlock it and make a part of mark sweep processing when the main block is accessed. > Actually this situation is not very unrealistic. __AXREGISTERHANDLER() > keeps block item. It is very natural, that this block will keep detached > object. > BTW, why "bbb destructor" is not printed in Test2? Is GT system down at > that time? No. Just simply it's executed when HVM is down what effectively disables executing .prg destructors so only array body is released. best regards, Przemek _______________________________________________ Harbour mailing list [email protected] http://lists.harbour-project.org/mailman/listinfo/harbour
