Bug 319969 (MONO77170) - [PATCH] set null to WeakReference.Target doesn't work
Summary: [PATCH] set null to WeakReference.Target doesn't work
Status: RESOLVED FIXED
Alias: MONO77170
Product: Mono: Runtime
Classification: Mono
Component: GC (show other bugs)
Version: 1.1
Hardware: Other Red Hat 9.0
: P3 - Medium : Minor
Target Milestone: ---
Assignee: Mono Bugs
QA Contact: Mono Bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-01-06 17:54 UTC by Oleg Burlachenko
Modified: 2007-09-15 21:24 UTC (History)
1 user (show)

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments
gc.diff (378 bytes, patch)
2006-01-08 01:12 UTC, Thomas Wiest
Details | Diff
gc2.diff (1.04 KB, patch)
2006-01-11 18:51 UTC, Thomas Wiest
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Wiest 2007-09-15 19:43:37 UTC


---- Reported by BurlachenkoO@mail.ru 2006-01-06 10:54:23 MST ----

Description of Problem:
set null to WeakReference.Target doesn't work

Steps to reproduce the problem:
I execute such code in C# console project:
using System;

namespace Mono_GC {
  class A{}

  class Class1 {

    [STAThread]
    static void Main(string[] args) {

      A a = new A();
      WeakReference weak = new WeakReference(a);
      Console.WriteLine("weak.Target = " + a);
      if(weak.Target != null)
        Console.WriteLine("weak.Target != null");
      else
        Console.WriteLine("weak.Target == null");

      weak.Target = null;
      Console.WriteLine("weak.Target = null");
      if(weak.Target != null)
        Console.WriteLine("test failed");
      else
        Console.WriteLine("test passed");

      Console.WriteLine("Weak reference test has been finished.");
    }
  }
}

Actual Results:
weak.Target = Mono_GC.A
weak.Target != null
weak.Target = null
test failed
Weak reference test has been finished.

Expected Results:
weak.Target = Mono_GC.A
weak.Target != null
weak.Target = null
test passed
Weak reference test has been finished.

How often does this happen? 
every run



---- Additional Comments From robertj@gmx.net 2006-01-07 18:12:10 MST ----

This is a minor bug in gc.c:mono_gchandle_set_target ()



---- Additional Comments From robertj@gmx.net 2006-01-07 18:12:59 MST ----

Created an attachment (id=169042)
gc.diff




---- Additional Comments From vargaz@gmail.com 2006-01-11 10:54:07 MST ----

This is ok to check in.




---- Additional Comments From vargaz@gmail.com 2006-01-11 10:57:18 MST ----

It may be better to add this mono_gc_weak_link_remove () in boehm-gc.c



---- Additional Comments From robertj@gmx.net 2006-01-11 11:50:48 MST ----

Like this?




---- Additional Comments From robertj@gmx.net 2006-01-11 11:51:29 MST ----

Created an attachment (id=169043)
gc2.diff




---- Additional Comments From vargaz@gmail.com 2006-01-18 10:32:42 MST ----

Yes.




---- Additional Comments From robertj@gmx.net 2006-01-18 11:25:38 MST ----

Fixed in SVN 55725.


Imported an attachment (id=169042)
Imported an attachment (id=169043)