To monitor the references I added some monitoring printf statements to the unref procedure.
In my template object selfreferences can only be created from within the object itself. I kept track of them in the selfrefcount variable at creation time. Myname contains the name of the object obtained using sprint(myname,"%s",this). The list
test is a list of objects that can hold a reference to the object in whose context we work and the cause of my unreferencing problem.
Code: Select all
proc unref(){local selfrefcount
refcount=$1
if(refcount==selfrefcount && selfrefcount > 0 && unreferencing==0){
unreferencing=1
test.remove_all()
printf( "Remove All")
printf( "ObjectName: %s, Refcount=%d, selfrefcount=%d \n",myname,refcount, selfrefcount)
}else{
printf( "ObjectName: %s, Refcount=%d, selfrefcount=%d \n",myname,refcount, selfrefcount)
}
}
When convinced that the references are managed correctly simply remove the printf statements. When things are not working correctly look both at the object and the code you use for testing, because it is so easy to oversee a reference lingering around.