Esempio n. 1
0
        public static void DebugFreeComObject <T>(ref T obj)
            where T : class
        {
            var localObj = Interlocked.Exchange(ref obj, null);

            // if it is already null -> return
            if (localObj == null)
            {
                return;
            }
            var hash = localObj.GetHashCode();
            // release
            int count = Marshal.ReleaseComObject(localObj);

            Console.WriteLine("ComRelease {0}({1}),rcw={2}", hash, typeof(T), count);

            XulObjectInfo info = null;

            if (_xulObjects.TryGetValue(hash, out info))
            {
                info.RcwCount = count;
                if (count == 0)
                {
                    _xulObjects.Remove(hash);
                }
            }
            else
            {
                Console.WriteLine("Untraced object free");
            }
        }
Esempio n. 2
0
        public static void WriteDebugInfo <T>(T xulrunnerObject)
            where T : class
        {
            int hashCode = xulrunnerObject.GetHashCode();
            int refCount = GetComRefCount(xulrunnerObject);
            int rcwCount = GetRcwRefCount(xulrunnerObject);

            Debug.WriteLine(string.Format("{0}({1}) - ref:{2},rcw:{3}", hashCode, typeof(T), refCount, rcwCount));

            XulObjectInfo info = null;

            if (_xulObjects.TryGetValue(hashCode, out info))
            {
                info.RefCount = refCount;
                info.RcwCount = rcwCount;
            }
            else
            {
                info          = new XulObjectInfo();
                info.ID       = hashCode;
                info.Type     = typeof(T);
                info.RefCount = refCount;
                info.RcwCount = rcwCount;
                _xulObjects.Add(hashCode, info);
            }
        }