Hello,
I'm just bitten by some occasional finalize exceptions in a wxd program
I'm writing on a OpenSuse 64 bit linux host with dmd 2.64.2.
I was able to track it down to a bug in wxd, where the wxObject
destructor tried to remove the object from a static map.
some code from wxObject:
~this()
{
Dispose();
}
public /+virtual+/ void Dispose()
{
if (wxobj != IntPtr.init)
{
// bool still_there = RemoveObject(wxobj);
// lock (typeof (wxObject)) {
if (memOwn /*&& still_there*/)
{
dtor();
}
// }
RemoveObject(wxobj);
wxobj = IntPtr.init;
// memOwn = false;
}
//GC.SuppressFinalize(this);
}
// Removes a registered object.
// returns true if the object is found in the
// Hashtable and is removed (for Dispose)
public static bool RemoveObject(IntPtr ptr)
{
bool retval = false;
if (ptr != IntPtr.init)
{
if(ptr in objects) {
//gw 20131207 objects.remove(ptr); <-- here the
application goes boom, so i replaced it with the following line
objects[ptr] = null;
retval = true;
}
}
return retval;
}
// Hashtable to associate C++ objects with D references
private static wxObject[IntPtr] objects;
As you can see, the problem is that wxObject destructor tried to remove
an entry from a static AA. Replacing the removal with just nulling the
value solves the problem. But now I have to implement a cyclic cleanup
routine wich removes the nulls from the AA. I really don't want to do that.
I suspect that the AA reorganized (with allocation) when an element is
removed. I think it is a good idee if this can be delayed until the next
insert, so that remove can be used in finalizers.
I also don't have a clue why the object gets collected when it is
referenced in the static map.
Gerrit Wichert