Hi,
recently I got a strange infinite loop in the garbage collector, by digging in the code i found that the problem is caused by a RemoveCPPOwnedGMObject. The condition seems quite rare and I am not sure if is caused by wrong usage of RemoveCPPOwnedGMObject.
We have a gmUserObject that holds a CPP object (a callback delegate object) that holds a GameMonkey function by using AddCPPOwnedGMObject. When the first gmUserObject is collected by GC and the Destruct function is called, the internal CPP object is released and his cpp destructor calls RemoveCPPOwnedGMObject to release the ownership of the gm function.
RemoveCPPOwnedGMObject internally write a barrier that change the order of the objects inside GC, but at that time we are inside a GC DestructSomeFreeObjects function that is iterating the objects and has references to m_next and m_prev. This condition can break the integrity of the internal list (maybe only when the two objects are consecutive).
This is just my supposition about what is happening but I am not 100% sure, Is our design wrong? Are we doing something that it is not suppose to be done?
Question: WriteBarrier purposes is just to have a GC don't miss any object right? What it does is just pop the object to the top of the gray objects so it is evaluated again. If WriteBarrier is not called what's happen is that an object that could be collected immediately will be collected later in another pass. Or I am missing something.
Thanks Paolo
|