Hello,

I've fixed an ugly leak(*) in Dictionary`2 today.  As the code of the
HashSet`1 class has been derived from the former class, it suffers from
the same memory leak.

The attached patch fixes this.
Place review.

- Juraj

*) see
https://bugzilla.novell.com/show_bug.cgi?id=384723 and
http://lists.ximian.com/pipermail/mono-patches/2008-April/116954.html
Index: System.Collections.Generic/HashSet.cs
===================================================================
--- System.Collections.Generic/HashSet.cs	(revision 101908)
+++ System.Collections.Generic/HashSet.cs	(working copy)
@@ -264,6 +264,8 @@
 			count = 0;
 			// clear the hash table
 			Array.Clear (table, 0, table.Length);
+			// clear all slots
+			Array.Clear (slots, 0, slots.Length);
 
 			// empty the "empty slots chain"
 			empty_slot = NO_SLOT;
@@ -320,6 +322,9 @@
 			links [current].Next = empty_slot;
 			empty_slot = current;
 
+			// clear empty slot
+			slots [current] = default (T);
+
 			generation++;
 
 			return true;
Index: System.Collections.Generic/ChangeLog
===================================================================
--- System.Collections.Generic/ChangeLog	(revision 101908)
+++ System.Collections.Generic/ChangeLog	(working copy)
@@ -1,3 +1,9 @@
+2008-04-29  Juraj Skripsky  <[EMAIL PROTECTED]>
+
+	* HashSet.cs (Clear, Remove): Clear empty slots. Otherwise
+	the garbage collector cannot reclaim the referenced value.
+	See bug #384723.
+
 2007-11-30  Jb Evain  <[EMAIL PROTECTED]>
 
 	* HashSet.cs: corcompare love.
_______________________________________________
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list

Reply via email to