Is there anyway to map the value returned by Runtime.ObjectID to the actual object?
I have a memory leak and I am keeping track of objects that aren’t being destroyed. I would like to know the object’s name and it’s value.
Also, since runtime.objectrefs tells us how many references there are to the object, is it possible to find out what is actually still referencing the object that isn’t being destroyed?
You ever get a good answer to this, Paul?
If ObjectID had been the handle, it would have been easy to get to the control name. Unfortunately that is not the case.
Instead of using Runtime.ObjectID create your own class that numbers instances. Keep track of them with WeakRefs and then you can go instance to number and vice versa.
To find what references an object run through an ObjectIterator using Introspection to find properties referencing that object.
[code]Function findRefsToObject(obj As Object) As Object()
dim ti As Introspection.TypeInfo, pa() As Introspection.PropertyInfo
dim foundReferrers(), c As Object, i As integer
dim iter As Runtime.ObjectIterator = Runtime.IterateObjects
while iter.MoveNext
c = iter.Current
ti = Introspection.GetType(c)
pa = ti.GetProperties
for i = 0 to pa.Ubound
if pa(i).Value(c) = obj then
foundReferrers.Append c
end
next
wend
return foundReferrers
End Function[/code]