[Mono-bugs] [Bug 651952] New: Memory leak: DataView is not garbage collected after it goes out of scope

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Sun Nov 7 15:28:32 EST 2010


https://bugzilla.novell.com/show_bug.cgi?id=651952

https://bugzilla.novell.com/show_bug.cgi?id=651952#c0


           Summary: Memory leak: DataView is not garbage collected after
                    it goes out of scope
    Classification: Mono
           Product: Mono: Class Libraries
           Version: 2.6.x
          Platform: x86
        OS/Version: Windows 7
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: Sys.Data
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: cvolzke at live.com.au
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---
           Blocker: ---


Created an attachment (id=398907)
 --> (http://bugzilla.novell.com/attachment.cgi?id=398907)
Proposed fix

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US)
AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.1.249.1036 Safari/532.5

DataView is not garbage collected after it goes out of scope.
This means:
a) There is a memory leak if creating and discarding data views over and over
b) It is not possible to make a DataView cache with weak references, the
DataViews are never collected.

This is contrary to ms.net behaviour which does not hold strong references to
DataViews.


Reproducible: Always

Steps to Reproduce:
Test case:

DataTable table = new DataTable();
DataView dataView = new DataView(table);
WeakReference dataViewRef = new WeakReference(dataView);
dataView = null;
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
Assert.AreEqual(false, dataViewRef.IsAlive, "DataView collected");

Actual Results:  
DataView is not garbage collected

Expected Results:  
DataView garbage collected after going out of scope

Proposed fixes
--------------

There's a few of ways I can think of to remove the strong reference to
DataViews:

1. Create a WeakEventHandler for dataset/table events, and use this specialized
handler to subscribe to events from DataView.
2. Create a class DataViewWeakEventHandlers that exposes ColumnChanged,
RowChanged etc, but holds onto DataView event handler delegates by weak
references. When an event is raised and the delegate weak reference is no
longer alive, the delegate is removed.
3. Create a class DataViewWeakEventHandlers that holds onto a single DataView
object by WeakReference, subscribes to dataset/table events and forwards them
to DataView internal event handler methods directly.

The DataViewWeakEventHandlers.cs class attached implements option #3.

-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list