[Mono-bugs] [Bug 70701][Cri] New - use of finalizers causes memory leaks
bugzilla-daemon@bugzilla.ximian.com
bugzilla-daemon@bugzilla.ximian.com
Mon, 20 Dec 2004 15:03:21 -0500 (EST)
Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.
Changed by will@cambia.com.
http://bugzilla.ximian.com/show_bug.cgi?id=70701
--- shadow/70701 2004-12-20 15:03:21.000000000 -0500
+++ shadow/70701.tmp.16133 2004-12-20 15:03:21.000000000 -0500
@@ -0,0 +1,93 @@
+Bug#: 70701
+Product: Mono: Runtime
+Version: 1.0
+OS: Red Hat 9.0
+OS Details: Fedora Core 2
+Status: NEW
+Resolution:
+Severity:
+Priority: Critical
+Component: misc
+AssignedTo: mono-bugs@ximian.com
+ReportedBy: will@cambia.com
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: use of finalizers causes memory leaks
+
+Description of Problem:
+
+Certain allocation patterns will cause mono to leak memory. The
+determining factors seem to be:
+a) program must allocate a lot of memory fairly quickly
+b) there must be some "big" allocations (50-100k)
+c) some of the objects allocated must have finalizers
+
+This bug makes out product unusable after several hours due to the
+machine swapping; the example code given here reproduces the same
+behavior much more quickly. Both our product and this example are OK
+under Microsoft's .NET.
+
+Steps to reproduce the problem:
+1. Compile the following program ("mcs MemWorkout.cs"):
+
+using System;
+using System.Collections;
+
+namespace MemWorkout {
+ class MemWorkout {
+ static void Main(string[] args) {
+ ArrayList al = new ArrayList();
+ Random r = new Random(30);
+ DateTime last = DateTime.Now;
+ while (true) {
+ Alloc(al, r);
+
+ DateTime now = DateTime.Now;
+ if (now.Subtract(last).TotalSeconds > 10) {
+ al.Clear();
+ last = now;
+ }
+ }
+ }
+
+ static int _cnt = 0;
+
+ static void Alloc(ArrayList save, Random r) {
+ Final f = new Final(r);
+ _cnt++;
+ if (_cnt == 50) {
+ save.Add(f);
+ _cnt = 0;
+ }
+ }
+ }
+
+ class Final {
+ public Final(Random r) {
+ _b = new byte[r.Next(100000)];
+ }
+
+ ~Final() {}
+
+ private byte[] _b;
+ }
+}
+
+2. Run under mono with no command-line arguments
+3. Observe the memory usage over time using top/ps/whatever.
+
+Actual Results:
+
+After 5 minutes or so on my system, mono is using all available system
+memory.
+
+Expected Results:
+
+Microsoft .NET continues to run the example indefinitely, as does mono if
+line 39 (~Final() {}) is commented out.
+
+How often does this happen?
+
+Every time.