[Mono-bugs] [Bug 670294] New: AddSubview and Garbage collection
bugzilla_noreply at novell.com
bugzilla_noreply at novell.com
Tue Feb 8 09:23:24 EST 2011
https://bugzilla.novell.com/show_bug.cgi?id=670294
https://bugzilla.novell.com/show_bug.cgi?id=670294#c0
Summary: AddSubview and Garbage collection
Classification: Mono
Product: MonoTouch
Version: unspecified
Platform: x86
OS/Version: Apple iOS 4.2
Status: NEW
Severity: Major
Priority: P5 - None
Component: Runtime
AssignedTo: mono-bugs at lists.ximian.com
ReportedBy: clementj at exactmodus.com
QAContact: mono-bugs at lists.ximian.com
CC: gnorton at novell.com
Found By: DeveloperNet
Blocker: No
Description of Problem:
Following a question on stackoverflow
(http://stackoverflow.com/questions/4902967/uiview-events-and-garbage-collection),
here is another case where it seems the memory is not garbage collected.
I have these two classes
public class CustomView : UIView
{
~CustomView (){ Console.WriteLine("~CustomView"); }
public event Action CustomEvent;
}
public class TestController : UIViewController
{
~TestController (){ Console.WriteLine("~TestController"); }
public CustomView Custom {get; set;}
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
Custom = new CustomView();
// When using AddSubview, I must either unregister the event handler or
remove
// CustomView from its superview.
Custom.CustomEvent += HandleEvent;
View.AddSubview(Custom);
}
private void HandleEvent(){ }
}
Steps to reproduce the problem:
My MainWindow has a NavigationController and it does the following:
1 - It pushed a new instance of TestViewController (thus only the
NavigationController has a reference to the TestViewController instance)
2- TestViewController is popped via the standard back button. Note that if I
don't use AddSubview, everything is collected as expected.
3 - When I return to the MainWindow, a button allows me to call GC.Collect just
to be sure.
Actual Results:
Neither finalizer is called (TestController or CustomView). In order to be
called, I need to either unregister the event handler or remove CustomView
from its superview.
--
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