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.
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?
Regards,
Mindaugas
-----------------------------------
#include "hbclass.ch"
PROC main()
LOCAL oB
? "Test1"
oB := BBB()
oB:aaa := {oB}
oB := NIL
? "oB is NIL"
HB_GCALL()
? "After GC"
? "Test2"
oB := BBB()
oB:aaa := ALLOCAAA(oB)
oB := NIL
? "oB is NIL"
HB_GCALL()
? "After GC"
RETURN
CREATE CLASS BBB
VAR aaa
DESTRUCTOR Destroy()
ENDCLASS
METHOD Destroy() CLASS BBB
? "bbb destructor"
RETURN NIL
#pragma begindump
#include "hbapi.h"
#include "hbapiitm.h"
typedef struct {
PHB_ITEM pItem;
} AAA;
static HB_GARBAGE_FUNC( hb_aaa_destructor )
{
AAA* pA = ( AAA* ) Cargo;
if( pA->pItem )
{
hb_itemRelease( pA->pItem );
pA->pItem = NULL;
}
printf("aaa destructor\n");
}
HB_FUNC( ALLOCAAA )
{
AAA* pA = ( AAA* ) hb_gcAlloc( sizeof( AAA ), hb_aaa_destructor );
pA->pItem = hb_itemNew( hb_param( 1, HB_IT_ANY ) );
hb_retptrGC( pA );
}
#pragma enddump
----------------------------------------
_______________________________________________
Harbour mailing list
[email protected]
http://lists.harbour-project.org/mailman/listinfo/harbour