[Mono-bugs] [Bug 670294] AddSubview and Garbage collection

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Wed Mar 16 15:27:21 EDT 2011


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

https://bugzilla.novell.com/show_bug.cgi?id=670294#c5


--- Comment #5 from David Notario <david.notario at gmail.com> 2011-03-16 19:27:20 UTC ---
I'm seeing what I think is the same problem and just attached a repro showing 3
event handling examples.

Basically, looks like when you add an event handler that somehow points back to
your object, a GC root is generated for that object that will stay alive when
it shouldn't.

Basically, the following pattern is broken:

- View A contains view B. A is the only GC root to B
- View A hooks to an event from B. Handler points to A (instance method or
anonymous delegate with 'this')
- View A becomes unreachable. 

Expected:
B becomes unreachable and all of A and B can be collected

Actual:
Unless handler is removed, A and B will leak.

The consequences are pretty bad for my project, as the workaround I have
requires me to change a lot of code.

a) Dispose must always be called to unhook the event handlers
b) I must resort to more cumbersome standalone event handlers instead of inline
delegates, which were a really great way to write code.

-- 
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