public bool UnArm(DefaultResourceLeak leak, ResourceLeakDetector owner, object referent)
            {
                lock (this.leakList)
                {
                    if (this.owner is null)
                    {
                        //Already disposed
                        return(false);
                    }
                    Debug.Assert(owner == this.owner);
                    Debug.Assert(referent == this.referent);

                    bool res = this.leakList.Remove(leak);
                    if (0u >= (uint)this.leakList.Count)
                    {
                        // The close is called by byte buffer release, in this case
                        // we suppress the GCNotice finalize to prevent false positive
                        // report where the byte buffer instance gets reused by thread
                        // local cache and the existing GCNotice finalizer still holds
                        // the same byte buffer instance.
                        GC.SuppressFinalize(this);

                        // Don't inline the variable, anything inside Debug.Assert()
                        // will be stripped out in Release builds
                        bool removed = this.owner.gcNotificationMap.Remove(this.referent);
                        Debug.Assert(removed);

                        //this.referent = null;
                        this.owner = null;
                    }
                    return(res);
                }
            }
Beispiel #2
0
            public DefaultResourceLeak(ResourceLeakDetector owner, object referent)
            {
                this.owner = owner;
                GCNotice existingNotice;

                if (owner.gcNotificationMap.TryGetValue(referent, out existingNotice))
                {
                    existingNotice.Rearm(this);
                }
                else
                {
                    owner.gcNotificationMap.Add(referent, new GCNotice(this));
                }

                if (referent != null)
                {
                    DetectionLevel level = Level;
                    if (level >= DetectionLevel.Advanced)
                    {
                        this.creationRecord = NewRecord(null);
                    }
                    else
                    {
                        this.creationRecord = null;
                    }

                    Interlocked.Increment(ref this.owner.active);
                }
                else
                {
                    this.creationRecord = null;
                    this.freed          = 1;
                }
            }
            public DefaultResourceLeak(ResourceLeakDetector owner, object referent)
            {
                this.owner = owner;
                owner.gcNotificationMap.Add(referent, new GCNotice(this));

                if (referent != null)
                {
                    DetectionLevel level = Level;
                    if (level >= DetectionLevel.Advanced)
                    {
                        this.creationRecord = NewRecord(null, 3);
                    }
                    else
                    {
                        this.creationRecord = null;
                    }

                    Interlocked.Increment(ref this.owner.active);
                }
                else
                {
                    this.creationRecord = null;
                    this.freed          = 1;
                }
            }
Beispiel #4
0
            public DefaultResourceLeak(ResourceLeakDetector owner, object referent)
            {
                Debug.Assert(referent != null);

                this.owner = owner;
                if (owner.gcNotificationMap.TryGetValue(referent, out GCNotice existingNotice))
                {
                    existingNotice.Rearm(this);
                }
                else
                {
                    owner.gcNotificationMap.Add(referent, new GCNotice(this, referent));
                }

                DetectionLevel level = Level;

                if (level >= DetectionLevel.Advanced)
                {
                    this.creationRecord = NewRecord(null);
                }
                else
                {
                    this.creationRecord = null;
                }
            }
            public DefaultResourceLeak(ResourceLeakDetector owner, object referent)
            {
                Debug.Assert(referent != null);

                this.owner = owner;
                if (owner.gcNotificationMap.TryGetValue(referent, out GCNotice existingNotice))
                {
                    existingNotice.Rearm(this);
                }
                else
                {
                    owner.gcNotificationMap.Add(referent, new GCNotice(this, referent));
                }
                this.head = RecordEntry.Bottom;
            }
            public bool Arm(DefaultResourceLeak leak, ResourceLeakDetector owner, object referent)
            {
                lock (this.leakList)
                {
                    if (this.owner is null)
                    {
                        //Already disposed
                        return(false);
                    }
                    Debug.Assert(owner == this.owner);
                    Debug.Assert(referent == this.referent);

                    _ = this.leakList.AddLast(leak);
                    return(true);
                }
            }
            public DefaultResourceLeak(ResourceLeakDetector owner, object referent)
            {
                Debug.Assert(referent is object);

                this.owner = owner;
                GCNotice gcNotice;

                do
                {
                    GCNotice gcNotice0 = null;
                    gcNotice = owner.gcNotificationMap.GetValue(referent, referent0 =>
                    {
                        gcNotice0 = new GCNotice(referent0, owner);
                        return(gcNotice0);
                    });
                    if (gcNotice0 is object && gcNotice0 != gcNotice)
                    {
                        GC.SuppressFinalize(gcNotice0);
                    }
                }while (!gcNotice.Arm(this, owner, referent));
                this.gcNotice = new WeakReference <GCNotice>(gcNotice);
                this.head     = RecordEntry.Bottom;
                Record();
            }
 public GCNotice(object referent, ResourceLeakDetector owner)
 {
     this.referent = referent;
     this.owner    = owner;
 }
Beispiel #9
0
 public GCNotice(object referent, ResourceLeakDetector owner)
 {
     _referent = referent;
     _owner    = owner;
 }